Reputation: 21
hello I want to send my gps coordinates and device id to the server. I am working on my server but just wanted to know if the code below is enough to post the coordinates..?
//get device id as following
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceid = telephonyManager.getDeviceId();
//this is JSON part to put your information inside it
String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"deviceid\":\""+deviceid+"\"}}";
HttpClient httpClient = new DefaultHttpClient();
// Post method to send data to server
HttpPost post = new HttpPost();
post.setURI(new URI("http://myserver.com/myphppage.php"));
// set your post data inside post method
post.setEntity(new StringEntity(postData));
// execute post request here
HttpResponse response = httpClient.execute(post);
Upvotes: 0
Views: 2031
Reputation: 46943
Just try it out.
Basically it depends on the schema with which you access the server (http
or https
), but if the connection is not secured, that's pretty much it.
Upvotes: 1