Java – Last.fm API calls from Android applications

Last.fm API calls from Android applications… here is a solution to the problem.

Last.fm API calls from Android applications

I’m trying to make a last.fm API call from an Android app using this package: http://www.u-mass.de/lastfm

From a simple Java command line program, it works but cannot be used in Android applications. Use Windows and Eclipse

The code itself is simple:

 Artist artist = Artist.getInfo("Depeche Mode", "my_key");

I’ve set internet permissions in the android manifest

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

After the call is over, I’ll print “Cache failed” here.
http://code.google.com/p/lastfm-java/source/browse/trunk/src/de/umass/lastfm/Caller.java?spec=svn173&r=173

The response code has -1

int responseCode = urlConnection.getResponseCode();

Know what I’m doing wrong?

Solution

I’m having the same issue.
This is a reported bug.

The solution I found was this:
Just add this line somewhere in your code, which will run before calling any API methods:
Caller.getInstance().setCache(null);

Note This disables caching…

For more information, check out this link

Related Problems and Solutions