Giter Site home page Giter Site logo

johnmaustin78 / android-java-snippets-rest-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoftgraph/android-java-snippets-rest-sample

0.0 1.0 0.0 492 KB

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 REST calls directly to the Microsoft Graph endpoint, and the Active Directory Authentication Library (ADAL) for authentication of users' work or school Office 365 accounts.

License: MIT License

Java 100.00%

android-java-snippets-rest-sample's Introduction

Office 365 Android Microsoft Graph Snippets

Table of contents

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

Users

Events

Messages

Contacts

Groups

Drives

Device requirement

To run the Microsoft Graph API REST snippets project, your device must meet the following requirement:

  • Android API level 16 or newer

Prerequisites

To use the Microsoft Graph API REST 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 developer site.
  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 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
  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 Android Microsoft Graph 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 ** O365-Android-Unified-API-Snippets** 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.o365_android_unified_api_snippets.snippet 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 Office 365 button to sign in to Office 365.
  3. Enter your credentials.
  4. Review and accept the permission scopes requested by the app.
  5. Click a REST operation in the main activity to show operation details.
  6. Click the RUN button to start the REST operation and wait for the operation to finish.
  7. Click in the Response Headers or Response Body text boxes to copy the box contents to the emulator/device clipboard.
  8. Click the back button on the REST Explorer toolbar to return to the REST operation list.
  9. (Optional) Click the overflow menu to get the Disconnect menu option.

How the sample affects your tenant data

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.

Understand the code

The Office 365 Android unified API snippets project uses these classes to manage interactions with the Microsoft Graph API on Office 365:

Sample project organization

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.

Modules in the Office 365 Android unified API snippets project

  • 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.

Snippet classes

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.

Microsoft Graph API service classes

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.

Authentication classes for Office 365 business accounts

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.

Questions and comments

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].

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 [email protected] with any additional questions or comments.

Additional resources

Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

android-java-snippets-rest-sample's People

Contributors

davidchesnut avatar iambmelt avatar keyur32 avatar o365devx avatar ricalo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.