Skip to content
This repository has been archived by the owner. It is now read-only.

Use Microsoft Graph to access a user’s Microsoft account data from within an Android app. This sample uses the Microsoft Graph Client Library to work with the data, and uses the Azure AD v2.0 endpoint for authentication of users of personal or work or school accounts.

master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Connect Sample for Android Using the Microsoft Graph SDK

Note: We've updated this sample to use the Microsoft Authentication Library (MSAL) for Android apps.

Building apps for enterprise customers? Your app may not work if your enterprise customer turns on enterprise mobility security features like conditional device access. In this case, you may not know and your customers may experience errors.

To support all enterprise customers across all enterprise scenarios, you must use the Azure AD endpoint and manage your apps using the Azure Management Portal. For more information, see Deciding between the Azure AD and Azure AD v2.0 endpoints.

Microsoft Graph Connect sample

Connecting to Microsoft Graph is the first step every Android app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through the Microsoft Graph SDK.

Device requirements

To run the Connect sample, your device needs to meet the following requirements:

  • A screen size of 800 x 480 or larger.
  • Android API level 16 or higher.

Prerequisites

To use the Connect sample for Android, you need the following:

Register and configure the app

  1. Open a browser and navigate to the Azure Active Directory admin center. Login using a Work or School Account.

  2. Select Azure Active Directory in the left-hand navigation, then select App registrations (Preview) under Manage.

    A screenshot of the App registrations

  3. Select New registration. On the Register an application page, set the values as follows.

    • Set a preferred Name e.g. AndroidJavaConnect
    • Set Supported account types to Accounts in any organizational directory.

    A screenshot of the Register an application page

  4. Choose Register. On the AndroidJavaConnect app page, select Overview and copy the value of the Application (client) ID and save it, you will need it in the next step.

    A screenshot of Application Id

  5. Still on the app page, select Authentication. Locate the section Redirect URIs. In the Suggested Redirect URIs for public clients(mobile,desktop), check the second box so that the app can work with the MSAL libraries used in the application. (The box should contain the option msal<YOUR_CLIENT_ID>://auth). Choose Save.

    A screenshot of Suggested Redirect URIs for Public Client

To learn about authenticating with MSAL for Android to make calls to Microsoft Graph, see Call the Microsoft Graph API from an Android app.

Open the sample using Android Studio

  1. Install Android Studio and add the Android SDK packages according to the instructions on developer.android.com.

  2. Download or clone this sample.

  3. Start Android Studio.

    1. Close any projects that you might have open, and then choose Open an existing Android Studio project.
    2. Browse to your local repository and choose the Android-Connect project. Click OK.

    Note: Android Studio shows a Frameworks detected notification if you don't have the Android Support Repository installed. Open the SDK manager and add the Android Support Repository to avoid the Frameworks detected notification.

  4. Open AndroidManifest.xml

    • Replace ENTER_YOUR_CLIENT_ID in two places with the application id from the previous section.
  5. Build the app and install the .APK on your device or emulator.

  6. Enable the Storage permission for the installed sample app on your device or emulator

  7. Download the test.jpg image located in: android-java-connect-sample/app/src/main/res/drawable/test.jpg to your device's external storage root folder.

Once you've built the Connect sample, you can run it on an emulator or device. Pick a device with API level 16 or higher from the Choose device dialog.

To learn more about the sample, see Call Microsoft Graph in an Android app.

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 Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.

Questions about Microsoft Graph development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [MicrosoftGraph] and [API].

Next steps

This sample just shows the essentials that your apps need to work with Microsoft Graph. There is so much more that your apps can do using the Office 365 APIs, like helping your users to manage their work day with calendar, find just the information they need in all the files they store in OneDrive, or find the exact person they need from their list of contacts. We have more to share with you in the Snippets sample for Android.

Additional resources

Copyright

Copyright (c) 2019 Microsoft. All rights reserved.

About

Use Microsoft Graph to access a user’s Microsoft account data from within an Android app. This sample uses the Microsoft Graph Client Library to work with the data, and uses the Azure AD v2.0 endpoint for authentication of users of personal or work or school accounts.

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.