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.
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.
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.
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.
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.
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.
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.
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
Rate this post: