Table of contents
- Device requirement
- Prerequisites
- Azure client application registration
- Configure the project
- Run the project
- How the sample affects your tenant data
- Understand the code
- Questions and comments
- Contributing
- Additional resources
Looking to build cool apps that help people work with their Office 365 data? Explore, learn, and understand the Microsoft Graph (previously called Office 365 unified API) REST APIs by using the Android Microsoft Graph API REST Snippets sample. This sample shows you how to access multiple resources, including Microsoft Azure Active Directory and the Office 365 APIs, by making HTTP requests to the Microsoft Graph API in an Android application.
You can explore the following operations for Office 365:
Me
- Get information about the signed in user.
- Get the user's responsibilities.
- Get the user's manager.
- Get the user's direct reports.
- Get the user's photo.
- Get the groups the user is a member of.
Users
- Get users from your tenant's directory.
- Get users filtered by criteria from your tenant's directory.
- Create a new user.
Events
- Get the signed-in user's events from Office 365.
- Create a new event for the user.
- Update a user's event.
- Delete a user's event.
Messages
Contacts
Groups
- Get all groups in your tenant's directory.
- Create a new group.
- Get information about a specific group in the tenant.
- Update the description of a group.
- Delete a group.
- Get a group's members.
- Get a group's owners.
Drives
- Gets the signed-in user's drive.
- Gets all of the drives in your tenant.
- Gets all of the files in the user's root folder.
- Creates a new file in the user's root folder.
- Downloads a file from the user's root folder.
- Updates the contents of a file in the user's root folder.
- Deletes a file in the user's root folder.
- Renames a file in the user's root folder.
- Creates a folder under the user's root folder.
To run the Microsoft Graph API REST snippets project, your device must meet the following requirement:
- Android API level 16 or newer
To use the Microsoft Graph API REST snippets project, you need the following:
- The latest version of Android Studio.
- The Gradle build automation system version 2.2.1 or later.
- An Office 365 account. You can sign up for an Office 365 Developer subscription that includes the resources you need to start building Office 365 apps.
- Java Development Kit (JDK) 7.
- A registered Azure application with a client id and redirect URI value. See Grant permissions to the Snippets application in Azure for details about how to create the correct permissions.
- Sign in to the Azure Management Portal, using your Azure AD credentials.
- Click Active Directory on the left menu, then select the directory for your Office 365 developer site.
- On the top menu, click Applications.
- Click Add from the bottom menu.
- On the What do you want to do page, click Add an application my organization is developing.
- On the Tell us about your application page, specify Android Snippet Sample for the application name and select NATIVE CLIENT APPLICATION for type.
- Click the arrow button on the bottom-right corner of the page.
- On the Application information page, specify a Redirect URI for example
http://localhost/androidsnippets
, and then select the check box in the lower-right corner of the page. - After the application has been successfully added, you will be taken to the Quick Start page for the application. From there, select Configure in the top menu.
- In the permissions to other applications section, add the Microsoft Graph application.
- For the Microsoft Graph application, add the following permissions:
- Sign in and read user profile
- Have full access to user files and files shared with user
- Have full access to user calendars
- Read and write access to user mail
- Send mail as a user
- Read user mail
- Read and write directory data
- Read all users' basic profiles
- Read and write all groups
- Click Save in the bottom menu.
- Note the values specified for Client ID on the Configure page. You will need these later when you configure the project.
- Download or clone the Android Microsoft Graph Snippets sample.
- Start Android Studio.
- From the Welcome to Android Studio dialog box, choose Import project (Eclipse ADT, Gradle, etc).
- Select the settings.gradle file in the ** O365-Android-Unified-API-Snippets** folder, and then click OK.
- Respond to the dialog box ("Gradle Sync: Gradle settings for this project are not configured yet. Would you like the project to use the Gradle wrapper? ") by clicking the OK button to use the Gradle wrapper.
- Open the ServiceConstants.java file in the com.microsoft.o365_android_unified_api_snippets.snippet package.
- Find the
CLIENT_ID
string and set its value to the client id you registered in Azure. - Find the
REDIRECT_URI
string and set its value to the redirect URI you registered in Azure.
After you've built the project you can run it on an emulator or device.
- Run the project.
- Click the Connect to Office 365 button to sign in to Office 365.
- Enter your credentials.
- Review and accept the permission scopes requested by the app.
- Click a REST operation in the main activity to show operation details.
- Click the RUN button to start the REST operation and wait for the operation to finish.
- Click in the Response Headers or Response Body text boxes to copy the box contents to the emulator/device clipboard.
- Click the back button on the REST Explorer toolbar to return to the REST operation list.
- (Optional) Click the overflow menu to get the Disconnect menu option.
This sample runs REST commands that create, read, update, or delete data. When running commands that delete or edit data, the sample creates fake entities. The fake entities are deleted or edited so that your actual tenant data is unaffected. The sample will leave behind fake entities on your tenant.
The Office 365 Android unified API snippets project uses these classes to manage interactions with the Microsoft Graph API on Office 365:
The Office 365 Android unified API snippets project is comprised of three modules. The modular design enables you to build a new app based on this sample by importing the modules into your app. After you've imported the modules, use the code in the Office 365 Android unified API snippets app module as an example of how to call methods in the other sample modules.
o365-Auth
. This module contains the library calls to authenticate a user with Office 365.unifiedapi
. This module encapsulates the Retrofit REST operations used for the Office 365 Microsoft Graph API endpoint.app
. The UI and business logic module. REST operations are started in the snippet classes in this module.
A snippet runs a single REST operation and returns the results. Snippets are found in the app module. Snippets set the state required to make the calls on the Microsoft Graph API service classes described below.
These classes are found in the unifiedapi module and make the Retrofit library calls that generate the REST queries and handle operation results. These service classes are consumed by the snippets.
MSGraphContactService
MSGraphEventsService
MSGraphGroupsService
MSGraphMailService
MSGraphUserService
The authentication classes are found in the o365-Auth module. These classes use the Microsoft Azure Active Directory Library (ADAL) for Android to connect to a business version of Office 365 such as Office 365 Enterprise.
AuthenticationManager
. Encapsulates user connect and disconnect logic in addition to Azure app authorization.AzureADModule
. Authentication helper class.AzureAppCompatActivity
. Dependency injection helper.
We'd love to get your feedback about the Android Microsoft Graph API REST Snippets sample. You can send your feedback to us in the Issues section of this repository.
General questions about Office 365 development should be posted to Stack Overflow. Make sure that your questions are tagged with [Office365] and [API].
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Copyright (c) 2015 Microsoft. All rights reserved.