Professional Documents
Culture Documents
Connecting To Web Services On Android 4577
Connecting To Web Services On Android 4577
HTTP request
XML response
http://code.google.com/p/jreeagle
jreeagle uses:
An open protocol to allow secure API authorization in a simple and standard method from desktop and web applications
use OAuth to access protected data your application needs to obtain an access
token from the service provider after the user grants permission
http://code.google.com/p/oauth
+ jreeagle
http://code.google.com/p/jreeagle/wiki/Android
jpoco
http://code.google.com/p/jpoco/wiki/Android
+ HTTP
Option 1
java.net.URL java.net.HttpURLConnection
Option 2
org.apache.http.client.HttpClient org.apache.http.impl.client.DefaultHttpClient
HttpClient programming
HTTP response status code I/O exceptions timeouts gzip?
HttpClient programming
synchronous invocation
public HttpResponse execute(HttpUriRequest request)
asynchronous invocation
public HttpResponse execute(HttpUriRequest request, ResponseHandler handler)
Android UI thread
user clicks on button onClick listener Dont block the UI thread! Tip: use java.lang.Runnable
Response formats
XML JSON RSS, Atom other
XML processing
org.w3c.dom package (DOM) org.xml.sax package (SAX) org.xmlpull package (XPP3) XStream JDOM Apache XmlBeans
*
JSON processing
org.json package Google GSON library XStream + Jettison json-lib
* * *
Client libraries
code.google.com/p/jreeagle code.google.com/p/jpoco code.google.com/p/meetup-java-client code.google.com/p/upcoming-java-client code.google.com/p/gdata-java-client ickrj.sourceforge.net
Conclusion
HttpClient API use XStream for XML processing use org.json package for JSON processing OAuth has a learning curve OAuth affects user experience
Thank you
Resources
http://code.google.com/android/documentation.html http://hc.apache.org/httpcomponents-client http://code.google.com/p/oauth http://xstream.codehaus.org