Solution: Well, http request isn't allowed on android 4.0 because it'll a long time and ui will freeze. It's necessary to start a new thread.
first of all, this is my first post, so sorry if I do something wrong.
Well, I'm trying to get a list of venues from foursquare for my app. I've searched a lot but I still not found an answer. This is the first time I use foursquare api and json, but I don't know where is the problem or if I'm doing something wrong. The code fails when I try to get the stream from the url (.openStream()). I'm trying to get the venues list with userless request.
so this is my code, if someone could help me, I'll be so greatful! Thank you.
String url = "https://api.foursquare.com/v2/venues/search?intent=checkin&ll="+str+"&client_id="+client_id+"&client_secret="+client_secret+"&v="+currentDateandTime+"&limit=15";
try{
URL urlend = new URL(url);
URLConnection urlConnection = urlend.openConnection();
InputStream in = (InputStream)urlend.openStream();
String JSONReponse = CharStreams.toString(new InputStreamReader(in, "UTF-8"));
JSONObject jsonObject = new JSONObject(JSONReponse);
JSONObject reponseJson= jsonObject.getJSONObject("reponse");
JSONArray arrayVenues= reponseJson.getJSONArray("venues");
final String[] names= new String[15];
final String[] venuesId= new String[15];
for (int i=0;i< arrayVenues.length(); i++)
{
JSONObject jObj= arrayVenues.getJSONObject(i);
names[i]= jObj.getString("name");
venuesId[i]= jObj.getString("id");
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
listView.setAdapter(adapter);
}
} catch(Exception e){
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
EDIT: I tried other solution from here:
http://stackoverflow.com/questions/7281283/android-webrequest-simple-solution
and when it executes that instruction "response = httpclient.execute(httpget);" jumps to catch again. And in this one
HttpClient httpclient = new DefaultHttpClient();
when I debug and I focus in it appears this http://i44.tinypic.com/33nyscg.png
There is something wrong?
Thank you.