Best option for using the GData APIs on Android?

前端 未结 5 1589
醉梦人生
醉梦人生 2020-12-04 11:32

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 andr

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 12:04

    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:

    
    

    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.

提交回复
热议问题