开发者

Passing data from intent to other using python server

开发者 https://www.devze.com 2023-03-14 16:58 出处:网络
I hav开发者_开发技巧e an application with an Android client and a Python server. The android package has three Activities, which access GPS and google maps. I send the GPS coordinates from the second

I hav开发者_开发技巧e an application with an Android client and a Python server. The android package has three Activities, which access GPS and google maps. I send the GPS coordinates from the second activity to the (python) server using a socket. I want to receive the [changed] value back from the server and pass it to the third Activity via an Intent to open the received location in a MapView.

What must be done in Android and on the server side to accomplish this.


The easiest way to do this would be to cut out your custom socket solution and replace it with a tiny web server. Obviously the task isn't going to have serious latency if the user is going to be seeing the result on a map in the near future, so HTTP is fine. Just make an http post request to the server, with longitude and latitude as input values in the post body. The response from the HTTP server should be another longitude and latitude, I am guessing. So you can receive those in the response, in JSON, would be nice:

{ "longitude" : 40.0, "latitude" : 31 }

Would be your response. You can parse that with JSONObject and you can use the Apache libraries to make your server requests. Once it is requested and parsed, you can pack the data into the extras of an Intent, and fire it off to the Activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号