Foreground service does not receive location updates in Doze mode in Android O

I have a foreground service that needs to receive one location update.

It is triggered by a specific broadcast, and when it starts, it just makes a request on our server. When it receives another broadcast, it requests a location update (once), makes another request to the backend, and then stops.

Edit: To clarify, the service itself does location updates and requests to the backend. In this respect, it does not depend on the main application.

This works well on Lollipop and Marshmallow, both when the phone is awake and in Doz mode. But for some reason on Android O, the service never gets location updates in Doz mode. The network works fine as its first request goes through in both situations. Also, if I wake up on the phone during a request to host it, it will get an update. The same if I put it in the maintenance window.

Android O does introduce some restrictions on the background layout , but as mentioned in this article, the behavior of the foreground app (the app is visible or running in the foreground) should be preserved and be similar to previous versions of Android.

Is this a problem in developer preview or a limitation I missed?

+3


source to share


1 answer


Take a look at LocationUpdatesForegroundService Example: Code samples for Android O , you might be wrong.

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



Get it on GitHub: Java

0


source







All Articles