Created
March 18, 2012 05:27
-
-
Save twaddington/2069153 to your computer and use it in GitHub Desktop.
Geoloqi Android SDK: POST Request
This file contains hidden or 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
// After binding to the tracking service you can | |
// perform a simple POST request using the runAPIRequest | |
// method. | |
// | |
// We'll be updating the SDK to provide simpler runGetRequest | |
// and runPostRequest methods to abstract away some of this | |
// logic. | |
if (mService != null) { | |
LQSession session = mService.getSession(); | |
// Build your request | |
HttpPost request = new HttpPost(); | |
try { | |
JSONObject geonote = new JSONObject(); | |
geonote.put("text", "Test!"); | |
geonote.put("latitude", 45.5037078163837); | |
geonote.put("longitude", -122.622699737549); | |
geonote.put("radius", 467); | |
geonote.put("place_name", "Grocery Store"); | |
request.setURI(new URI("https://api.geoloqi.com/1/geonote/create")); | |
request.setEntity(new StringEntity(geonote.toString(), HTTP.UTF_8)); | |
// Set the request content-type | |
request.addHeader("Content-Type", "application/json"); | |
} catch (URISyntaxException e) { | |
// Pass | |
} catch (JSONException e) { | |
// Pass | |
} catch (UnsupportedEncodingException e) { | |
// Pass | |
} | |
// Send the request | |
session.runAPIRequest(request, new OnRunApiRequestListener() { | |
@Override | |
public void onComplete(HttpResponse response) { | |
try { | |
Log.d(TAG, EntityUtils.toString(response.getEntity())); | |
} catch (ParseException e) { | |
// Pass | |
} catch (IOException e) { | |
// Pass | |
} | |
} | |
@Override | |
public void onFailure(LQSession session, LQException e) { | |
// Pass | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment