Firstly, Google Drive has been part of Android for some time now. That means you don't have to download any additional SDK since all you need is the Google Play Services library that comes bundled with every Eclipse/ADT installation.
1) Set up the Google Play Services project as a library in your Eclipse workspace (for a breakdown of the steps involved, see this guide), and add it to the Google Drive Quickstart Android application (download it here)
2) Create a new project in the Google Developers Console.
3) We are interested in giving our app access to our users' folders and files on Google Drive, so we need to enable OAuth.
Once your project from Step 2 has been created, go to Credentials and click "Create new client ID."
4) Select "Installed Application", select "Android" and then enter the package name as well as the signing certificate fingerprint.
For Debugging:
Open your console, and type in the following command:
Copy the SHA1 key and paste it into the Google Developers Console.
For Production:
Before you can enter these though, you'll need to go back to Eclipse/ADT and sign your app. Select the project, then click on File > Export. Select Export Android Application, and then select the project you want to sign. Create a new keystore and then create a new key as shown in the images below.
Export the package as an .apk file:
You should see the Client ID on the page after you submit the required information.
To read more on what you just did, click here.
5) Make sure you go into Google Developers Console and turn on access to the Drive API under your project (select your project, click on "APIs and auth" in the left naviation pane, and then select "APIs"). Note that there are two things: Drive API and Drive SDK. Earlier, I kept getting an error that looked like this:
Ultimately I realized that this was because I'd turned on Drive SDK, but not Drive API. So to save yourself some hassle, just turn both on.
6) Also put in your email address and product name in "Consent Screen" under "APIs and Auth". Apparently if you don't do that it won't work - there are lots of posts on forums about this.
7) Run the application (right click on the project > run as > android application) and it should work! It will prompt you to select a Google account on your phone, and then ask you to grant consent to the app. Finally you'll be able to take photos using your phone and upload them to Google Drive.
And that's it! You have gotten Google Drive working on Android.
No comments:
Post a Comment