发布
社区首页 >问答首页 >Android Oreo 2小时后停止的背景位置更新

Android Oreo 2小时后停止的背景位置更新
EN

Stack Overflow用户
提问于 2018-02-22 05:21:02
回答 1查看 4.5K关注 0票数 5

安卓8 (Oreo)推出了一些背景执行和位置限制。有两种方法来请求位置更新--通过前台请求的活套和对后台请求的待决意图 (即BroadcastReceiver)。

如果您的应用程序在后台运行,定位系统服务每小时只为您的应用程序计算几次新的位置。

The problem:当应用程序进入后台模式时,我会收到大约2个小时的位置更新,直到我再次打开应用程序之后才会收到任何更新。我的LocationRequest设置没有指定任何过期时间,因此,我期望无限期地接收位置更新。

代码语言:javascript
代码运行次数:0
复制
val locationRequest =  {
        val mLocationRequest = LocationRequest()
        mLocationRequest.interval = 4.minutes()
        mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
        mLocationRequest.maxWaitTime = 10.minutes()
        mLocationRequest.fastestInterval = 30.seconds()
        mLocationRequest
    }()

val intent = Intent(this, BackgroundLocationUpdatesReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
LocationServices.getFusedLocationProviderClient(mContext).requestLocationUpdates(locationRequest, pendingIntent)

我正在考虑对电池进行一些优化,以便对此负责(即。但其他应用程序也在发送通知,因此,它不在Doze中,而处于待机状态的应用程序并不重要,因为它是通过PendingIntent发送给BroadcastReceiver的。

EN

回答 1

Stack Overflow用户

发布于 2018-02-22 05:49:13

可能的解决方案将是Firebase作业调度程序。您可以安排一项在每2小时或1小时后开始服务的作业。

启动后台服务的逻辑可能会有所不同。我假设这一点,因为我看到whatsapp是在后台消息运行在我的设备上的某个时间间隔,这是有O更新。

您可以签出Firebase dispatcher 这里。

其他替代办法在奥利奥的后台服务。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48920167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档