我正在为我的公司(自己公司的设备)创建一个设备跟踪应用
我使用 GooglePlay API
创建了一个后台服务来获取更新。
但是,当我的应用程序关闭时,它很少将位置发送到服务器。它很少获得更新更新。
我该怎么办?我可以使用任何特殊权限吗?
最佳答案
使用WorkManager以此目的。即使您的应用程序被终止,WorkManager 中安排的进程也会被执行。
在您的情况下,您可以安排以固定的时间间隔检查位置并将其发送到服务器或您想要发送的任何地方。
来自官方文档:
The WorkManager API makes it easy to specify deferrable, asynchronous tasks and when they should run. These APIs let you create a task and hand it off to WorkManager to run immediately or at an appropriate time. For example, an app might need to download new resources from the network from time to time. Using these classes, you can set up a task, choose appropriate circumstances for it to run (like "only while device is charging and online"), and hand it off to WorkManager to run when the conditions are met. The task is still guaranteed to run, even if your app is force-quit or the device is rebooted.
您的任务将属于 Recurring tasks
关于java - 永不关闭的位置后台服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51664062/