Foreground service not receiving location updates in Doze mode in Android O

风流意气都作罢 提交于 2019-12-01 07:01:25

问题


I have a foreground service that needs to get a single location update.

It is started by a specific broadcast, and upon starting it simply does a request on our backend. When it receives another broadcast, it requests a location update (once), does another backend request and then stops itself.

Edit: to clarify, the service itself does the location updates and backend requests. It is independent from the main app in that regard.

This works well on Lollipop and Marshmallow, both when the phone is awake or in Doze mode. But for some reason, on Android O the service never gets location updates when in Doze mode. Networking works fine as its first request goes through in both situations. Also, if I wake up the phone while the location request it running, it will get the update. Same if I put it in maintenance window.

Android O does introduce some limitations on background location but as the page mentions, the foreground app behavior (app visible or foreground service running) should be preserved and be similar to previous versions of Android.

Is this an issue in the developer preview or a restriction that I missed?


回答1:


Take a look on LocationUpdatesForegroundService Sample: Code Samples for Android O, maybe you do something wrong.

LocationUpdatesForegroundService Sample - Shows how to use a foreground service to get location updates when the app activities are not visible. For apps running on Android O (even apps that target Android 7.0 (API level 24) or lower), background updates are limited to only a few times per hour. Using a foreground service is a way to receive more frequent updates.

Get it on GitHub: Java



来源:https://stackoverflow.com/questions/44811812/foreground-service-not-receiving-location-updates-in-doze-mode-in-android-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!