简体   繁体   English

Android设备中的实时数据通信

[英]Real-time Data Communication in Android Devices

Basically I want to track another device using Google Maps with the help of a GPS. 基本上,我想在GPS的帮助下使用Google Maps跟踪其他设备。 Can you give me an advice on how I could do it efficiently? 您能给我一些有关如何有效做到的建议吗?

What I have in mind is: I will write the longitude and latitude of the device I want to track in a remote database. 我要记住的是:我将在远程数据库中写入要跟踪的设备的经度和纬度。 And the other will fetch the data every 5 sec or something. 另一个将每5秒钟或大约5秒钟获取一次数据。

Is that efficient? 这样有效吗? Or there are other ways to send the coordinates directly to the other device? 还是有其他方法可以将坐标直接发送到其他设备?

Thanks! 谢谢!

Choice depends on the time interval selected for location submission and its polling from other client. 选择取决于为位置提交选择的时间间隔以及从其他客户端进行的轮询。

If its every 3 minute (Realistic i feel) or more. 如果它每3分钟(我觉得很现实)或更长时间。 I guess normal http submission to your remote server and fetching the same using http could do the trick. 我想正常的HTTP提交到您的远程服务器,并使用http来获取相同内容就可以了。 That would be super easy implementation to what you want to achieve. 那将是您想要实现的超级容易的实现。

But if you are looking for something real time like instant messaging thing. 但是,如果您正在寻找即时消息之类的实时内容。 You have to go for xmpp connections. 您必须进行xmpp连接。 openfire server implementation and smack library could be helpful for you. openfire服务器实施和smack库可能对您有所帮助。

here are the links. 这里是链接。

Download server from here 从这里下载服务器

http://www.igniterealtime.org/projects/openfire/ http://www.igniterealtime.org/projects/openfire/

check client code from here 从这里检查客户端代码

http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application

Replace google credentials with your local openfire server created one and ip and port respectively. 将Google凭据替换为分别创建的本地openfire服务器one和ip和port。

Following the above two only. 以下仅是以上两个。 I created a simple chat application for android along with server following the above in hardly 3 hours. 我在不到3小时的时间内按照上述步骤为服务器创建了一个简单的android聊天应用程序。 Go ahead and try by your self. 继续尝试自己。

Hope it helps 希望能帮助到你

I propose setting the location change listener to react on a minimum distance, not only on time interval. 我建议将位置更改侦听器设置为在最小距离上做出反应,而不仅仅是在时间间隔上做出反应。 The posting client may be static for some time, fetching GPS and sending it is a waste of cpu time, bandwidth and battery. 发布客户端在一段时间内可能是静态的,因此获取GPS并将其发送会浪费CPU时间,带宽和电池。

Also, 5 seconds can be a short time. 同样,5秒可能是短时间。 It can drain battery and consume bandwidth quite fast. 它会耗尽电池并很快消耗带宽。

If you are certain you have to track the client always when the application is started, then a periodical post is ok. 如果确定必须在启动应用程序时始终跟踪客户端,那么可以定期发表文章。 If the receiving phone only needs the location from time to time, than a pull request would be more economical (ie he should request the location from another phone). 如果接收电话不时仅需要该位置,则比拉取请求更为经济(即,他应从另一部电话请求该位置)。

And finally, this might be handy: http://googlecloudplatform.blogspot.com/2013/06/get-your-mobile-application-in-the-cloud-with-mobile-backend-starter.html . 最后,这可能很方便: http : //googlecloudplatform.blogspot.com/2013/06/get-your-mobile-application-in-the-cloud-with-mobile-backend-starter.html The example is actually something you are building, of not the same. 该示例实际上是您正在构建的东西,不尽相同。

PS There is no way to send data "directly" to another phone (except if it is always connected to the same hotspot with a public IP address and reserved local IP, which is not the case 99% of the time). PS无法将数据“直接”发送到另一部电话(除非它始终使用公共IP地址和保留的本地IP连接到同一热点,而99%的情况并非如此)。 That means you should use Google Cloud Messaging or a similar implementation. 这意味着您应该使用Google Cloud Messaging或类似的实现。

我认为最好使用推送通知 ,将服务器通过http查询发送到设备命令“给我您的位置”和设备应答服务器,例如,也可以轻松地将获取数据的时间从5秒更改为30秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM