Using the Google API Client Library for Java on Android

If you are developing for Android and the Google API you want to use is included in the Google Play Services library, use that library for the best performance and experience. If the Google API you want to use with Android is not part of the Google Play Services library, you can use the Google API Client Library for Java, which supports Android 4.0 (Ice Cream Sandwich) (or higher), and which is described here.

Getting started

Begin by reading the Android development instructions for the Google HTTP Client Library for Java.


As described in the Android development instructions, the best practice on Android is to use the AccountManager class (@Beta) for centralized identity management and credential token storage.

OAuth 2.0
For information about the OAuth 2.0 flow, see the OAuth 2.0 instructions for Android.

Partial response and update

Google APIs support a partial-response protocol that allows you to specify which fields are returned to you in the HTTP response. This can significantly reduce the size of the response, thereby reducing network usage, parsing response time, and memory usage. It works with both JSON and XML.

The following snippet of code drawn from the Google+ Sample demonstrates how to use the partial-response protocol:

Plus.Activities.List listActivities = plus.activities().list("me", "public");
// Pro tip: Use partial responses to improve response time considerably
ActivityFeed feed = listActivities.execute();


A good example that uses the generated service-specific library is tasks-android-sample. Another example can be found in calendar-android-sample, which mixes ClientLogin with the service-specific library.

2011 video

In this hour-long video from Google I/O 2011, Yaniv Inbar describes programming guidelines for accessing Google APIs on Android.

Caution: Some of the code snippets in the video are outdated, although the guidelines are still relevant.