Created
May 23, 2013 06:48
-
-
Save taywils/5633162 to your computer and use it in GitHub Desktop.
QueryGooglePlaces doInBackground Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Based on: http://stackoverflow.com/questions/3505930 | |
*/ | |
private class QueryGooglePlaces extends AsyncTask<String, String, String> { | |
@Override | |
protected String doInBackground(String... args) { | |
HttpClient httpclient = new DefaultHttpClient(); | |
HttpResponse response; | |
String responseString = null; | |
try { | |
response = httpclient.execute(new HttpGet(args[0])); | |
StatusLine statusLine = response.getStatusLine(); | |
if(statusLine.getStatusCode() == HttpStatus.SC_OK){ | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
response.getEntity().writeTo(out); | |
out.close(); | |
responseString = out.toString(); | |
} else { | |
//Closes the connection. | |
response.getEntity().getContent().close(); | |
throw new IOException(statusLine.getReasonPhrase()); | |
} | |
} catch (ClientProtocolException e) { | |
Log.e("ERROR", e.getMessage()); | |
} catch (IOException e) { | |
Log.e("ERROR", e.getMessage()); | |
} | |
return responseString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment