Android App: Setting up Google APIs Client Library for Java [Part 2]

posted in: Uncategorized | 0
  1. Android App: Preparing to Access Google Drive
  2. Android App: Setting up Google APIs Client Library for Java
  3. Android App: Connecting to Google Drive with Google APIs Client Library for Java

If you are using Gradle skip ahead.

As of writing the current version of Google APIs Client Library for Java is 1.17.0-rc, released in September 12, 2013. For those that are not using Gradle with Android (which you should), extract the zip file (google-api-java-client-1.17.0-rc.zip) contents into the “libs” folder. If you do not, you will get a NoClassDefFoundError at runtime when trying to access Google Drive. Below are the files which are needed to connect to Google Drive using OAuth2 on Android:

Next you need to copy the Google Play Services libraries into the project “libs” folder. Which can be found in the following path:
ANDROID_SDK\extras\google\google_play_services\libproject\

In the AndroidManifest.xml add the following to get access to Google Play Services:

Using the Google Play Services requires you to follow the Attribution Requirements found on Google Developers website:

In Part 3, discussion would be on using Android to connect to Google Drive with Google APIs Client Library for Java.

Gradle

With Gradle you do not need to download Google APIs Client Library for Java and to copy the Google Play Services. In the build.gradle file include the following dependencies to access Google Drive:

The first dependency, com.google.android.gms:play-services:4.+, is for Google Play Services and the next one, com.google.apis.google-api-services-drive:v2-rev113-1.17.0-rc, is to get Google Drive access. The three remaining dependencies are for making OAuth2 connection using AndroidHTTP, GoogleAccountCredential, and GsonFactory.

In the AndroidManifest.xml add the following to get access to Google Play Services:

Using the Google Play Services requires you to follow the Attribution Requirements found on Google Developers website:

In Part 3, discussion would be on using Android to connect to Google Drive with Google APIs Client Library for Java.