在Android的定期发送当前位置到服务器 [英] Send Current Location to server periodically in android

查看:489
本文介绍了在Android的定期发送当前位置到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要送我的当前位置信息(纬度和放大器;长)定期向服务器(例如:每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

<一个href="http://stackoverflow.com/questions/2775628/android-how-to-periodically-send-location-to-a-server">Android:如何周期性地发送位置服务器

<一个href="http://developer.android.com/reference/android/app/AlarmManager.html">http://developer.android.com/reference/android/app/AlarmManager.html

<一个href="http://developer.android.com/reference/android/app/Service.html">http://developer.android.com/reference/android/app/Service.html

这篇关于在Android的定期发送当前位置到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆