java - 永不关闭的位置后台服务

标签 java android android-location

我正在为我的公司(自己公司的设备)创建一个设备跟踪应用

我使用 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/

相关文章:

java - bazel - netty_tcnative 错误

java - 将人类时间与计算机时间结合成合成时间

java - 单击按钮时,为什么我的应用程序会崩溃?

android - 使用 GoogleApiClient + LocationServices 不更新

java - 部署maven项目到tomcat

android - 是否有可能在 Android 的 locktask/kiosk 模式下隐藏导航栏中的后退键图标?

android - 编辑文本 : how to display the number while you are typing it?

android - 从坐标获取位置

android - 应用程序被杀死时地理围栏不起作用

java - 使用 DefaultDesktopManager 的 JInternalFrame 图标化异常