Re: [android-alliance] REST API calls in Android

1,136 views
Skip to first unread message

Chuck Greb

unread,
May 10, 2013, 8:36:40 AM5/10/13
to android-allian...@googlegroups.com
Check out http://square.github.io/okhttp/. There are some very good examples on the site.


On Fri, May 10, 2013 at 8:26 AM, Sam Beckley <sbec...@friendscentral.org> wrote:
Hey all, completely new Android Developer here, still learning the basics.  I'm trying to connect my app to a web-based REST API, so far with no success.  I've looked into using Robospice, but after spending a couple days with that it's only made things more complicated.  How do you handle making API calls? Is there a great service to simplify it or do you just write the code yourself? 

Thanks! 

--
You received this message because you are subscribed to the Google Groups "Android Alliance Philadelphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-alliance-phi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Chuck Greb

Sam Beckley

unread,
May 10, 2013, 2:12:38 PM5/10/13
to android-allian...@googlegroups.com
Thank you! I've been playing around with this, and it looks great, but I'm hitting an error I've hit before with my other projects, when I send the program to the Android Emulator the .jar files I'm using don't also get sent.  I'm working in Eclipse and I added them to the Java build path as their guide suggests, but when I run it I get a LogCat error that the emulator can't find the library.  Do you know what I'm doing wrong? Is it necessary to use the <uses-library/> tag in my manifest?


On Friday, May 10, 2013 8:36:40 AM UTC-4, Chuck Greb wrote:
Check out http://square.github.io/okhttp/. There are some very good examples on the site.
On Fri, May 10, 2013 at 8:26 AM, Sam Beckley <sbec...@friendscentral.org> wrote:
Hey all, completely new Android Developer here, still learning the basics.  I'm trying to connect my app to a web-based REST API, so far with no success.  I've looked into using Robospice, but after spending a couple days with that it's only made things more complicated.  How do you handle making API calls? Is there a great service to simplify it or do you just write the code yourself? 

Thanks! 

--
You received this message because you are subscribed to the Google Groups "Android Alliance Philadelphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-alliance-philadelphia+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chuck Greb

unread,
May 10, 2013, 2:54:59 PM5/10/13
to android-allian...@googlegroups.com
You do not need the <uses-library/> tag in the manifest for java libraries like OkHttp. This tag is only for special libraries like Google Maps that need to be present on the device or emulator.

Sounds like a build config issue with Eclipse/ADT but I won't be much help with that since I use IntelliJ/Maven.


To unsubscribe from this group and stop receiving emails from it, send an email to android-alliance-phi...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Arpit Mathur

unread,
May 11, 2013, 12:05:42 AM5/11/13
to android-allian...@googlegroups.com
Sam, don't use the "Add Library.." part in the guide. If you are just trying to compile with the .jar, just add the jar to the project

I pushed a sample project to github for using OkHTTP. See here:



Gotchas:
1) Make sure you have added the OKHTTP jar in the libs folder inside your project.
2) Make sure to add the jar in your application's Java build settings.
Inline image 1

3) Make sure to add the "uses internet" permission in your android app (see the AndroidManifest.xml file in the project)
4) Make sure you use the square library in an AsyncTask or a thread (my example uses the AsyncTask). Since Android 4.0, Android will not allow you to make a network call to get data on the UI thread. Otherwise the UI thread (which is responsible for responding to user events like updating the interface when the user clicks around or scrolls, etc) will get blocked and your app will appear frozen

If you want to import the OkHTTPTest project, just download it from Github and in eclipse you can do File > Import project. Let me know how that goes.



image.png

Samuel Beckley

unread,
May 13, 2013, 2:00:04 PM5/13/13
to android-allian...@googlegroups.com
Thanks Arpit! That worked like a charm. Now I'm looking into parsing the returned data, do you have an suggestions? Currently the webpage is returning me JSON, but I'm having issues parsing that, so I've started looking into XML instead. Thank you again!


You received this message because you are subscribed to a topic in the Google Groups "Android Alliance Philadelphia" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-alliance-philadelphia/an_Xb8m3Dns/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to android-alliance-phi...@googlegroups.com.
image.png
Reply all
Reply to author
Forward
0 new messages