views:

4545

answers:

3

What's the least painful and most size efficient way to use the Google Data APIs in an Android application?

After a few quick searches t seems that there is an android-gdata project on Google Code that seems to be the work of a single author. I didn't find any documentation for it and don't even know if it's production ready yet.

An older option, the com.google.wireless.gdata package seems to have been removed from the SDK. It's still available in the GIT repository.

Before I invest too much time with either approach I'd like to know which is the best supported and least painful.

+4  A: 

I also looked at the google-code project and the git repo. I steered away from the google-code project due to the apparent baggage that came along in required projects. I ended up creating custom implementations as necessary to adapt the standard java API. You can find a rough description of my solution in the android-developers group. It is 4 short, easily tested classes

James A Wilson
+7  A: 

Please take a look at the Google API Client Library for Java which supports Android:

http://code.google.com/p/google-api-java-client/

It also supports new GData technologies like the recently announced partial response/update and JSON-C, both of which can be a dramatic improvement in efficiency on Android.

To start, take a look at Android sample for Picasa Web Albums Data API.

Full disclosure: I am an owner of the google-api-java-client project.

Yaniv Inbar
This looks great. Thanks for the link!
Erich Douglass
You'll need the Javamail dependency if you're working with Google Docs: http://www.oracle.com/technetwork/java/index-138643.html otherwise you get a MediaStreamSource error in logcat
Chris S
Chris, no, there is no dependency on Javamail in the google-api-java-client library, and there is no MediaStreamSource. That's only a problem in the old gdata-java-client library.
Yaniv Inbar
@Yaniv is that something the 1.10 Alpha has?
Chris S
+1  A: 

Here's some steps to getting the Google Docs api working with an Android Eclipse project.

Spoiler: it breaks (for me) on the SAX exception

1

Get the GData Java library (via the language guide)

2

Get the 3 jars from the Android Javamail port

3

Add the following jars in your lib folder, add them to the path using the context menu (Build path->Add)

  • activation.jar (javamail)
  • additionnal.jar (javamail)
  • mail.jar (javamail)
  • gdata-client-1.0.jar
  • gdata-client-meta-1.0.jar
  • gdata-core-1.0.jar
  • gdata-docs-3.0.jar
  • gdata-docs-meta-3.0.jar
  • gdata-gtt-2.0.jar
  • gdata-gtt-meta-2.0.jar
  • gdata-media-1.0.jar
  • google-collect-1.0-rc1.jar (from the deps folder of the gdata folder)
  • jsr305.jar3. (from the deps folder of the gdata folder)

4

Don't forget to add the INTERNET permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

5

Try out some example code:

DocsService client = new DocsService("myappname");
try
{
    client.setUserCredentials("username", "password");

    URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/");
    DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);

    TextView textView = (TextView) findViewById(R.id.textview);

    String text = ""; 
    for (DocumentListEntry entry : feed.getEntries())
    {
        text += entry.getTitle().getPlainText() + "\r\n";
    }

    textView.setText(text);
}
catch (AuthenticationException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
catch (MalformedURLException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
catch (IOException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
catch (ServiceException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}

6

Accept defeat after 2 hours, with a SaxException from logcat:

WARN/XmlParser(1599): javax.xml.parsers.ParserConfigurationException:
org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
...
at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)

This last step causes a ServiceException.

Chris S
Right, the gdata-java-client library doesn't support Android. This is a known problem. Instead, you should use google-api-java-client. By the way, the download link needs to be corrected to http://code.google.com/p/google-api-java-client/downloads/list
Yaniv Inbar
@Yaniv I fixed the link. Don't you find it a bit strange that their own devices don't have native support? Perhaps they have big plans for it and prefer not to get apps for GDocs etc.
Chris S