Our Blog

where we write about the things we love

08

Dec

Developing Office 365 apps on Android and iOS

With the recent release of Android and iOS SDKs for Office 365 you can access OneDrive for Business, SharePoint, Exchange and Azure Active Directory directly from your Android or iOS app. In this blog post you will find out how to start creating your own apps.

Office 365 is Microsoft’s productivity platform in the cloud, including OneDrive for Business, Exchange for calendars and email, SharePoint for document collaboration and Azure Active Directory for federated identity. 

Developed by Microsoft Open Technologies, the Office 365 SDKs for Android and iOS provide native APIs for data from the HTTP/REST services exposed by each of the platforms:

  • Office 365 SharePoint Lists
  • Office 365 SharePoint Files (a.k.a. OneDrive for Business)
  • Office 365 Exchange Calendar, Contacts and Email

The SDKs are broken up into a separate library for each service, and can be included as required. Below you will find the basics to get your apps connected to these services and running in no time.

Office 365 SDK for Android

The Office 365 SDK for Android provides a pure-Java library for connecting to and consuming Office 365 services from your Android or Java app. The library has full support for Android Studio. Adding any of the libraries in the SDK as a dependency is as simple as adding a few lines to your build.gradle file.

Adding Office 365 SDK libraries to Android build.gradle

User authentication is handled by the excellent Active Directory Authentication Library for Android. This library implements the OAuth 2.0 authentication process and supports things like two-factor authentication. The ADAL automatically takes care of securely caching auth tokens, and will only prompt the user for their credentials if necessary.

Office 365 OAUTH Android authentication

In order to authenticate with Office 365 you need to register the application with Azure Active Directory for your Office 365 Tenancy. In this way you have granular control over the permissions the app is given to each of the services in your tenancy. You can of course manage this directly through the Azure Management Portal.

Registering Office 365 Android app with Azure Active Directory

With the hard stuff out of the way, actually making calls to the Office 365 APIs is simple: Construct a *Client object, pass in the access token obtained using the ADAL and start invoking the strongly-typed API it exposes.

Collection operations such as filtering, sorting and paging are exposed through a fluent “builder” API which will be familiar to Android developers.

Calling Office 365 API from Android app

All of the libraries in the SDK are non-blocking, making use of Google’s Guava library for asynchronous primitives. Every function which makes an asynchronous API call returns a Future object, to which you can attach callbacks to handle the eventual result. This means you can always avoid blocking the UI thread, though you do have to be careful to marshal work back to the UI thread when the callbacks are fired.

Office 365 API calls from Android code are asynchronous, using Guava library

You can find a reference Android starter application here.

Office 365 SDK for iOS

The Office 365 SDK for iOS provides an Objective-C library for connecting to and consuming Office 365 services from an iOS app. The SDK is distributed using the Cocoapods dependency manager, so installing it is as simple as adding a few lines to your Podfile and running pod install in a terminal.

Adding Office 365 dependencies to podfile 

The Office 365 SDK for iOS relies on the Active Directory Authentication Library for Objective-C for authentication, which is also installed via Cocoapods.

The steps for configuring your app for authentication with Office 365 are identical to those for Android, as are those for making calls to the Office 365 APIs: Construct a *Client object, passing in the access token obtained using the ADAL and start calling API methods it provides.

Collection operations such as filtering, sorting and paging are exposed through a fluent “builder” API using a similar pattern to the Android libraries.

The SDK is also fully asynchronous. Every remote call accepts a callback block for handling the result (or any errors). As with Android, you must be careful to dispatch back to the UI thread.

Office 365 API calls from iOS app 

Unfortunately the iOS SDK does not provide full access to the SharePoint Lists API. There is a preliminary client for this API in the SDK, but it isn’t really ready for primetime yet – for most operations you’ll find yourself manually building queries against the HTTP API and parsing the results. 

For more information about developing on the Office 365 platform, check out the documentation on MSDN.

Posted by: Benjamin Fox, Modern Applications Developer | 08 December 2014

Tags: Office 365, Mobile applications, mobility, Android, iOS


Top Rated Posts

Blog archive

Stay up to date with all insights from the Intergen blog