43

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.

nyenyec
  • 7,138
  • 9
  • 29
  • 15
  • 3
    I'd also like to know the answer to this - I'm quite surprised that the Android API does not include even a subset of the Gdata API, why not bundle these phenomenally useful components! – Salim Fadhley Jan 06 '10 at 00:06
  • 2
    It's amazing that the device that it's currently hardest to develop gdata apps for is Android, and the loops you have to jump through – Chris S Sep 28 '10 at 19:34

5 Answers5

32

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

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, please take a look at the Android Developer's Guide. Also, please look at the Android sample for Picasa Web Albums Data API, which demonstrates the ability create/update/delete a photo album and to upload a picture.

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

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
Yaniv Inbar
  • 1,409
  • 9
  • 10
  • 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 Sep 28 '10 at 18:10
  • 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 Oct 04 '10 at 19:02
  • @Yaniv is that something the 1.10 Alpha has? – Chris S Oct 05 '10 at 08:15
  • @Yaniv, does the new Android API supports client login? – mudit Nov 03 '10 at 12:06
  • Yes, although on Android you need to use the AccountManager. See http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager – Yaniv Inbar Nov 13 '10 at 14:33
  • @Yaniv Inbar can you check my problem m geeting in your api http://stackoverflow.com/q/7230435/689853 – Harinder Aug 30 '11 at 09:05
  • 7
    I'm confused. I want to get Google Spreadhseets data from an Android environment. Yaniv's google-api-java-client link is to a page which in turn links to "list of Google APIs we support", including the Spreadsheets API, at http://code.google.com/apis/spreadsheets. Its developer's guide "Getting Started" section says to download the gdata-java-client library to access the API, and all the examples seem to be gdata-java-client dependent (e.g., com.google.gdata.data.spreadsheet.*). However, @Yaniv says below "the gdata-java-client library doesn't support Android". What am I missing? – joseph_morris Oct 20 '11 at 02:52
5

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
  • 14,611
  • 5
  • 29
  • 31
3

Please try Google SpreadSheet API for Android

I am maintaining this project on Google Code, so if you face any problem, kindly let me know.

Cheers, Prasanta

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
user542954
  • 512
  • 4
  • 2
  • This works pretty well. You just have to comment out a couple of lines that point to a proxy server that Prasanta appears to have inadvertently left in the released code, in order to speed up response time (like, one minute vs. two seconds). See issue 13 in Google Code at the link above for the fix. – joseph_morris Oct 20 '11 at 02:57
2

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
  • 64,770
  • 52
  • 221
  • 239
  • 1
    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 Oct 04 '10 at 19:05
  • @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 Oct 04 '10 at 20:50
  • @Chris S i used yuor example but i am getting AuthenticationException error connecting to login URI – Harinder Aug 30 '11 at 05:37
  • lolz.. I spent more than 2 hours before reaching step 6 and accepting defeat. Now starting with google-apis.. step 1. ;) – vivek.m Sep 17 '11 at 20:39
1

I used this API

I tried converting it to a .jar, but had problems. I found it easy to mark the project as a library project and then used it in my main project.

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
Clive Jefferies
  • 1,138
  • 14
  • 26