且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何持续追踪安卓手机的位置?

更新时间:2023-02-26 21:34:59

您的代码可能是正确的,但是当您的手机处于睡眠状态时,位置提供程序没有运行.您可能需要获取唤醒锁(如果您不关心功耗),或者使用 AlarmManager 并安排您的应用程序唤醒并定期检查位置(在等待更新时您仍然需要激活唤醒锁,或者由 AlamManager 或您自己获得).

Your code is probably correct, but location providers are not running when your phone is sleeping. You may need to acquire a wakelock (if you don't care about power draw), or use AlarmManager and schedule your application to wake up and check location periodically (you still need to have active wakelock while you are waiting for an update, either acquired by AlamManager, or your own).