Sunday, July 28, 2013

Reading Google Spreadsheets from an Android App

Well, I've done it. It took me two serious days of wading through the mess that is the gdata APIs (myths and outdated versions abound) and the OAuth2 APIs (same caveats apply) and I was finally able to read the list of my own personal spreadsheets in Google Docs, and print their names out from an Android application.

It was very important to me to be able to use Android's own build-in account mechanism, which took a fair bit of time to figure out, and then on top of that the build/class-path requirements for the Google Spreadsheets API is completely messed up.

But anyway, here's a short description of how I did it, notes, and the full code for the main activity.

1 - I am using a Nexus 4, so I set up my app to use the latest APIs possible (Android 4.2.2 on my system).

2 - The list of required JARs is crazy, and quite picky. Here's the screenshots of the ones I am using:

3 - I had to add the following permissions to my manifest file:

4 - And finally, here is the code itself to run the main activity. The basic application structure was just the one that is created by default when you create a new Android Application. The basic steps for listing the Spreadsheets I got from the Spreadsheets API Tutorial. I can't really remember where I learned the OAuth2.0 steps, but needless to say, I cobbled it together from several online sources.