Android:手机处于 sleep 状态时GPS位置更新?

标签 android locationmanager

即使手机处于 sleep 状态,我也需要在后台通过 GPS 更新位置。我正在考虑使用 AlarmManager 广播一个 Intent,然后接收器将调用 LocationManager 上的 requestLocationUpdates()。但是我不确定如果我在调用 requestLocationUpdates() 时注册了 PendingIntent,是否可以保证在手机处于 sleep 状态时更新 GPS 位置并广播 intent?

谢谢,

最佳答案

你可以使用 service .

A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class.

如果您的手机进入休眠状态,该服务将在后台继续工作。请记住使用 startService() 启动服务而不是 bindService()否则,当启动服务的 Activity 进入休眠状态时,服务将停止。

希望这对您有帮助..

关于Android:手机处于 sleep 状态时GPS位置更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3010011/

相关文章:

javascript - 从 javaScript Phonegap 上传文件的方法

android - 如何在 ionic1.0.0_beta.14 上调整底部的选项卡

android - 突出显示 "ListFragment"中的选定项目?

swift - 无法使用 Swift 获得正确的位置

codenameone - 使用 LocationManager 获取当前位置

java - 在 EditText 中显示地址在真实设备上不起作用

android - 如何更好地处理GPS定位和android

Android 'debuggable' 默认值

android - onLocationChanged 从未调用过?

java - Android:getContext().getContentResolver() 有时会出现 NullPointerException