Skip to content

Code snippets that use the Microsoft Graph to perform common tasks, such as sending email or managing groups, from within an Android app. This sample uses the Microsoft Graph Client Library to work with the data, and the Active Directory Authentication Library (ADAL) for authentication of users' work or school Office 365 accounts.

License

Notifications You must be signed in to change notification settings

JohnMAustin78/android-java-snippets-sample

 
 

Repository files navigation

Snippets Sample for Android Using the Microsoft Graph SDK

Build Status

Table of contents

Looking to build cool apps that help people work with their Office 365 data? Explore, learn, and understand the Microsoft Graph SDK by using this Snippets sample. This sample shows you how to access multiple resources, including Microsoft Azure Active Directory and Office 365, by making calls to the Microsoft Graph SDK in an Android application.

You can explore the following operations in Microsoft Graph:

Me

Users

Events

Messages

Groups

Drives

##Device requirement To run snippets project, your device must meet the following requirement:

  • Android API level 16 or newer

###Prerequisites To use the Microsoft Graph SDK snippets project, you need the following:

##Azure client application registration

  1. Sign in to the Azure Management Portal, using your Azure AD credentials.
  2. Click Active Directory on the left menu, then select the directory for your Office 365 tenant.
  3. On the top menu, click Applications.
  4. Click Add from the bottom menu.
  5. On the What do you want to do page, click Add an application my organization is developing.
  6. On the Tell us about your application page, specify Android Snippet Sample for the application name and select NATIVE CLIENT APPLICATION for type.
  7. Click the arrow button on the bottom-right corner of the page.
  8. 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.
  9. 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.
  10. In the permissions to other applications section, add the Microsoft Graph application.
  11. For the Microsoft Graph application, add the following permissions:
  • Sign in and read user profile
  • Have full access to all files user can access
  • 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
  1. Click Save in the bottom menu.
  2. Note the values specified for Client ID on the Configure page. You will need these later when you configure the project.

##Configure the project

  1. Download or clone the snippets sample.
  2. Start Android Studio.
  3. From the Welcome to Android Studio dialog box, choose Import project (Eclipse ADT, Gradle, etc).
  4. Select the settings.gradle file in the android-java-snippets-sample folder, and then click OK.
  5. 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.
  6. Open the ServiceConstants.java file in the com.microsoft.graph.snippets package.
  7. Find the CLIENT_ID string and set its value to the client id you registered in Azure.
  8. Find the REDIRECT_URI string and set its value to the redirect URI you registered in Azure.

##Run the project After you've built the project you can run it on an emulator or device.

  1. Run the project.
  2. Click the Connect to Microsoft Graph button to sign in.
  3. Enter your credentials.
  4. Review and accept the permission scopes requested by the app.
  5. Click an operation in the main activity to show operation details.
  6. Click the RUN button to start the operation and wait for the operation to finish.
  7. Click in the Raw Object text box to copy the box contents to the emulator/device clipboard.
  8. Click the back button on the toolbar to return to the operation list.
  9. (Optional) Click the overflow menu to get the Disconnect menu option.

##How the sample affects your tenant data This sample runs 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.

##Understand the code The snippets project uses these classes to manage interactions with Microsoft Graph:

###Sample project organization The snippets project is comprised of two 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 snippets app module as an example of how to call methods in the other sample modules.

###Modules in the snippets project

  • o365-Auth. This module contains the library calls to authenticate a user with Microsoft Graph.
  • app. The UI and business logic module. SDK operations are started in the snippet classes in this module.

###Snippet classes A snippet runs a single 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 service classes described below.

###Authentication classes 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 Microsoft Graph.

Contributing

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 opencode@microsoft.com with any additional questions or comments.

Questions and comments

We'd love to get your feedback about the Microsoft Graph SDK Snippets sample for Android. You can send your feedback to us in the Issues section of this repository.
General questions about Microsoft Graph development should be posted to Stack Overflow. Make sure that your questions are tagged with [microsoftgraph].

Additional resources

Copyright (c) 2015 Microsoft. All rights reserved.

About

Code snippets that use the Microsoft Graph to perform common tasks, such as sending email or managing groups, from within an Android app. This sample uses the Microsoft Graph Client Library to work with the data, and the Active Directory Authentication Library (ADAL) for authentication of users' work or school Office 365 accounts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 99.3%
  • Other 0.7%