在Android的定期发送当前位置到服务器当前位置、服务器、Android

2023-09-04 04:00:52 作者:不要你的理睬

我要送我的当前位置信息(纬度和放大器;长)定期向服务器(例如:每5分钟)。有什么最好的方法?我知道如何获得当前位置和放大器;如何将信息发送到服务器。但我怎么在周期性间隔重复此?

I have to send my current location details (lat & long) to server periodically (Ex: for every 5 minutes). Is there any best way? I know how to get the current location & how to send the details to server. But how do I repeat this in periodic intervals?

推荐答案

使用 AlarmManager 5分钟后醒来时,用户打开应用程序第一次注册报警。创建服务(读取位置,并更新到服务器)时,报警器会通知您的应用程序运行。在服务完成了工作,注册一个再次报警5分钟后醒来。通过这种方式,你可以实现你的任务。

Register an alarm using AlarmManager to wake up after 5min when user open the application first time. create a service(fetch location and update to server) to run when alarm notifies your application. After the service finished the work , register for an alarm again to wake up after 5min. by this way you can achieve your task.

REF

Android:如何周期性地发送位置服务器

http://developer.android.com/reference/android/app/AlarmManager.html

http://developer.android.com/reference/android/app/Service.html