Last.fm API call from Android application - java

I'm trying to make last.fm API call from android application using this package: http://www.u-mass.de/lastfm
From simple java command line program, it works, but not in android application. Using windows and Eclipse
Code itself is very easy:
Artist artist = Artist.getInfo("Depeche Mode", "my_key");
I have set internet permission in android manifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
After call I end up here, where it prints "caching failed."
http://code.google.com/p/lastfm-java/source/browse/trunk/src/de/umass/lastfm/Caller.java?spec=svn173&r=173
response code there is -1
int responseCode = urlConnection.getResponseCode();
Any ideas what I'm doing wrong?

I was facing the same problem.
Its a reported bug.
Solution I found was this :
Just add this line somewhere in your code that will get run prior to calling any of the api methods:
Caller.getInstance().setCache(null);
Note: this will disable Caching..
for more info check this link

Related

Android App doesn't have internet connection - No Permissions required

Well, I have built an app to store values on a remote database. It works!! I didn't use an emulator for testing instead I used my own phone. Now the problem is that on my phone, it works perfectly...no issues but when I installed it on another phone, the app doesn't connect to the internet.
I have included internet permission in android manifest.xml.
I have tried these but didn't work:
Building apk and installing in the new phone.
Compiling directly to the new phone.
Sending the apk from old phone to new phone via shareit.
Creating a signed apk and installing.
Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).
Checked android compatibility: supports up to android 10.
*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. and the catch exception for no internet returns connection problem. I'm getting that error message.
As I researched, I got to know that internet permission is categorized as normal permission which is not prompted to the user upon installation.
I built a second dummy app: Same issue with it... compiled directly to new phone but didn't work...it works in old phone...
Old phone: Samsung J7 Prime with Android 8.1
New Phone: Samsung J7 Pro with Android 9
Any idea or suggestion will be gladly helpful... Thank you!
in android 9 and above you have to set network Security Config
first of all in res package create xml package and in xml package create new xml resource file with network_security_config name
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
then in manifest in
android:networkSecurityConfig="#xml/network_security_config"
<uses-permission android:name="android.permission.INTERNET" />
Use debug APK instead of signed APK
please add permission on Manifest to give a permission of permission.INTERNET

android get restful api always timeout

I use httpclient(apache) to get a restful API when developing an Android app,just like
HttpGet httpget = new HttpGet("http://9.123.151.73:4414/apiv1/data");
HttpResponse response = httpclient.execute(httpget);
and the xml,I have set the permission:
`<uses-permission android:name="android.permission.INTERNET" />`
but it always timeout.
Then I try these cases:
Open the url in browser,it works
New a simple java project with the same code, it works
Replace the url with other rest API ,such as:
http://api.search.yahoo.co/NewsSearchService/V1/, works
So, could you give me any advices for this problem,I wonder why the rest API can not be used in Android app,what is the mistake?
I beleive it is due to the permission not set to make network connections. Here is what you need to add to your AndroidMainfest.xml file to allow access to the internet:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Here is the permission description:
INTERNET Allows applications to open network sockets.
You can check more about the permission from the link:
Here is how you can set the permission if you are using eclipse:
If you are using the Eclipse ADT plugin for your development, open
"AndroidManifest.xml" in the Android Manifest Editor (should be the
default action for opening androidmanifest.xml from the project files
list), select the "Permissions" tab along the bottom of the editor
(Manifest - Application - Permissions - Instrumentation -
AndroidManifest.xml), then "Add..." a "Uses Permission" and select the
desired permission from the dropdown on the right, or just copy paste
in the necessary one (such as the "android.permission.INTERNET"
permission you required
http://developer.android.com/reference/android/Manifest.permission.html

Problems running demo application

As far as I can determine I have followed the steps as detailed at https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0200_DevKits_for_Intuit_Partner_Platform/Sample_Apps/Java_Sample_App_for_AggCat_Services/0010_Creating_the_App for running the java demo application.
After enabling the logs, I see following entries in the log output
DEBUG: com.intuit.aggcat.logger - Response code=401
DEBUG: com.intuit.aggcat.logger - OAuth access tokens = null
DEBUG: com.intuit.aggcat.logger - Could not get oAuth tokens: null
So I think server thinks I don't have permissions, however intuit developer website shows I have test access permissions for Customer Account Data API. Can someone please let me know what I am doing wrong.
By the way I think documentation at above link is cut off. Very Last statement says "run as" but does not say run as what
I would recommend that you try using the API explorer (developer.intuit.com/apiexplorer) with the same set of keys to verify that the keys and cert used are correct. If you are able to retrieve the tokens through the API Explorer, then you should be able to do the same through the Java sample app.
You should login to the sample app with the username "user"

Trouble getting blackberry json parsing code sample to work

I'm working on the Blackberry Eclipse plugin but can't get this sample to work :
Code sample: Parsing a JSON data structure
It doesn't go anywhere after response = bsd.sendReceive();
The Simulator has internet access in the browser, and I also checked the "Launch Mobile Data System Connection Service (MDS-CS) with simulator." (odd that nothing shows up in fiddler, but hey)
The URI does seem to timeout quite often so I changed it to point to a file in my dropbox, but that didn't change anything.
Anyone have any success running this sample ?
added ";deviceside=true" to uri

Android, UnknownHostException: www.google.com, on device,not emulator

I'm using google api java client for connecting to Google Docs in Android app.
Once in a while i get following exception:
UnknownHostException: www.google.com
Code:
transport = AndroidHttp.newCompatibleTransport();
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "writely";
authenticator.username = username.getText().toString();
authenticator.password = password.getText().toString();
authenticator.transport = transport;
authenticator.authenticate().getAuthorizationHeaderValue();
Device reset clears exception but is it necessary.
I suspected for DNS caching and tried following but didnt work. Im not behind a proxy as far I know.
Security.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.negative.ttl","0");
System.setProperty("net.eth0.dns1","8.8.8.8");
System.setProperty("net.dns1","8.8.8.8");
Last time it occurred was this morning when one network connection "died", cell auto got second one, tried to do ClientLogin but failed with exception.
Just to make it clear, Im talking about DEVICE (htc desire hd), not emulator.
Thanks in advance.
add this line to your AndroidManifest.xml file, just after the <manifest> tag and before the <application> tag:
<uses-permission android:name="android.permission.INTERNET" />
I run into this daily. I think it is a bug in the emulator. After reset of emulator it works again and it never happened on a real device.
Edit: most definitely a bug in the emulator. See this thread. There are also several posts on StackOverflow regarding those emulator connection issues.

Categories

Resources