- Android App: Preparing to Access Google Drive
- Android App: Setting up Google APIs Client Library for Java
- 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:
1
2
3
4
5
6
7
8
9
10
11
12
|
google-api-client-1.17.0-rc.jar
google-api-client-android-1.17.0-rc.jar
google-api-services-drive-v2-rev113-1.17.0-rc.jar
google-http-client-1.17.0-rc.jar
google-http-client-android-1.17.0-rc.jar
google-http-client-gson-1.17.0-rc.jar
google-oauth-client-1.17.0-rc.jar
gson-2.1.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
jackson-core-2.1.3.jar
jsr305-1.3.9.jar
|
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:
1
2
3
|
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
|
Using the Google Play Services requires you to follow the Attribution Requirements found on Google Developers website:
123 If you use the Google Drive Android API in your application, you must include the Google Play Services attribution text as part of a "Legal Notices" section in your application. Including legal notices as an independent menu item, or as part of an "About" menu item, is recommended.The attribution text is available by making a call to GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo.
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:
1
2
3
4
5
6
7
8
9
10
11
12
|
...
apply plugin: 'android'
...
dependencies {
...
compile 'com.google.android.gms:play-services:4.+'
compile 'com.google.apis.google-api-services-drive:v2-rev113-1.17.0-rc'
compile 'com.google.http-client:google-http-client-android:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client-android:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client-gson:1.17.0-rc' exclude module: 'httpclient'
...
}
|
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:
1
2
3
|
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
|
Using the Google Play Services requires you to follow the Attribution Requirements found on Google Developers website:
123 If you use the Google Drive Android API in your application, you must include the Google Play Services attribution text as part of a "Legal Notices" section in your application. Including legal notices as an independent menu item, or as part of an "About" menu item, is recommended.The attribution text is available by making a call to GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo.
In Part 3, discussion would be on using Android to connect to Google Drive with Google APIs Client Library for Java.