Table of contents
- Change History
- Device requirements
- Setting up your environment
- Running the starter project
- Understanding the code
- Questions and comments
- Additional resources
There are millions of Office 365 users with data in the cloud; imagine building an Android app that gives your customers new and innovative ways to work with their files stored on OneDrive for Business or their calendars stored in Office 365 Exchange. The Office 365 SDK starter project shows you how to use the Office 365 SDK for Android from Microsoft Open Technologies, Inc (MS Open Tech) to integrate your users' Office 365 and OneDrive for Business data into your app. You can use the starter project as a starting point for your own app; or you can just cut and paste the parts that you want to use.
The starter project shows you basic operations using the Files and Calendar service endpoints on Office 365. It also demonstrates how to authenticate with multiple Office 365 services in a single app. The starter project operations include:
Calendar
- Get existing calendar events.
- Create new events.
- Update events.
- Delete events.
OneDrive for Business Files
- Get existing files and folders.
- Create text files.
- Delete files or folders.
- Read text file contents.
- Update text file contents.
We'll be updating the starter project to add other services, such as Email, so make sure to check back.
## Change History December 19, 2014:- Added smartphone layout support. The sample now runs on both tablets and smartphones in landscape or portrait mode.
- Added paging of events to Calendar client.
- A screen size of 4 inches or larger.
- Android API version 18 or later.
To use the Office 365 APIs starter project for Android you need the following:
- The latest version of the Android Developer Tools including Eclipse.
- An Office 365 account. You can sign up for an Office 365 Developer subscription that includes all of the tools and resources that you need to start building and testing Android apps.
- The Active Directory Azure Library for Android. You'll need to either clone the repository or download the zip file.
- The Office 365 SDK for Android. You'll need to either clone the repository or download the zip file.
The details of configuring the Android starter project depend on your current development environment. While we can't give you detailed instructions, we can give you the basic steps that you need to follow.
- Install and configure the Android Developer Tools and Eclipse according to the instructions on developer.android.com.
- Sign up for a developer account on Office 365.
- Create a new client application in Azure.
- In the Azure management portal, select the Active Directory tab and an Office 365 tenant.
- Choose the Applications tab and click Add.
- In the What do you want to do screen click Add an application my organization is developing.
- Add the name of your application. If you're using the starter project, the name should be O365-Android-Start. Click NATIVE CLIENT APPLICATION and then click the next arrow.
- Add a redirect URI. The URI does not need to link to an actual resource, but it does need to be a valid SSL URI. Try "https://localhost/starterproject", for example. Click the check mark to finish adding the application.
- Open the application that you just created and click Configure. Make a note of the application's client ID, you'll need that later to configure the starter project.
-
Grant permissions to your client application.
-
In the Azure management portal, select the Active Directory tab and an Office 365 tenant.
-
Choose the Applications tab and click the application that you want to configure.
-
In the permissions to other applications section, add the following two permissions.
- Add the Office 365 SharePoint Online application (1), and select the Edit or delete users' files permission (2).
- Add the Office 365 Exchange Online application (3), and select the Have full access to users' calendars permission (4).
-
Save the changes.
-
-
Download or clone the Active Directory Azure Library for Android.
-
Start Eclipse and create a new workspace for your app.
-
Import the AuthenticationActivity project from the Active Directory Azure Library into your new workspace.
-
Add the Android support library to the AuthenticationActivity project. To do this, right-click the project, choose Android Tools, and then Add Support Library.
-
Download the latest version of the gson library.
-
Add the gson jar file to the libs folder of the AuthenticationActivity project.
-
Download or clone the Office 365 Starter Project for Android.
-
Import the starter project into your Eclipse workspace.
-
Download the latest guava library.
-
Add the guava jar file to the libs folder of the o365-android-start project.
-
Add the jar files from the Office 365 SDK for Android. Either download the jar files from Bintray, or clone and build the Office 365 SDK for Android, and then copy the jar files to your project.
To download the jar files: Download the jar files for the Office 365 SDK for Android from Bintray You need to add the following jar files to the libs folder of the starter app so that it compiles and runs correctly:
- odata-engine-android-impl-0.9.3.jar
- outlook-services-0.9.3.jar
- file-services-0.9.3.jar
- discovery-services-0.9.3.jar
Note: You can use version 0.9.3 or later of the jars.
To build the jar files:
- Clone the Office 365 SDK for Android.
- Go to the sdk directory.
- Run
.\gradlew clean
. - Run
.\gradlew assemble
.
-
Open the constants.java file in the com.microsoft.office365.starter package.
-
Find the CLIENT_ID constant and set its String value equal to the client id you registered in Azure Active Directory.
-
Find the REDIRECT_URI constant and set its String value equal to the redirect URI you registered in Azure Active Directory.
Once you've built the starter project you can run it on an emulator or device.
- Run the project.
- Click the "Sign in" button and enter your credentials.
- Click the calendar or file button to start working with your data.
The starter project uses two objects, O365FileListModel and O365CalendarModel to manage interactions with Office 365. These two objects wrap calls to the SharePointClient and OutlookClient objects in the Office 365 SDK for Android. Look at the O365APIsStart_Application.getFileClient()
and O365APIsStart_Application.getCalendarClient()
methods to see how the SDK
objects are created.
The Office 365 SDK for Android uses the Azure Active Directory Library (ADAL) for Android for authentication. The ADAL provides protocol support for OAuth2, Web API integration with user level consent, and two-factor authentication.
The Authentication object manages getting a token from ADAL and returning it to your application.
### Calendar APIThe O365CalendarModel object wraps the API operations that create, update and delete calendar events in an Office 365 Exchange calendar.
The getEventList(int pageSize,int skipToEvent) method gets a list of events from the Office 365 calendar and loads pages of events into a local list. Changes, deletions, and additions to this list are posted asynchronously to the Office 365 calendar by the postUpdatedEvent, postDeletedEvent, and postCreatedEvent methods.
### Files APIThe O365FileListModel object wraps the API operations that create, update, and delete files stored on OneDrive for Business.
The getFilesAndFoldersFromService method gets a list of all of the files and folders that are stored on OneDrive for Business and loads the list into a local array. Changes, deletions, and additions to the local list of files are posted asynchronously to OneDrive for Business by the postUpdatedFileContents, postDeleteSectectedFileFromList, and postNewFileToServer methods.
The getFileDetailsFromService method returns an O365FileModel object containing the selected files contents.
## Questions and commentsWe'd love to get your feedback on this Android starter kit. You can send your questions and suggestions to us:
- In the Issues section of this repository.
- On Stack Overflow. Make sure that your questions or comments are tagged with [Office365] and [API].
- Office 365 APIs documentation
- File REST operations reference
- Calendar REST operations reference
- Microsoft Office 365 API Tools
- Office Dev Center
- Office 365 APIs starter projects and code samples
Copyright (c) Microsoft. All rights reserved.