4

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?

Jukurrpa
  • 4,038
  • 7
  • 43
  • 73

1 Answers1

0

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

phnmnn
  • 12,813
  • 11
  • 47
  • 64
  • I was using a `PendingIntent` (remnant from when my service was a background one), I replaced it with a `LocationCallback` along with the service's `Looper` as they do but it did not fix the issue. – Jukurrpa Jul 15 '17 at 00:34
  • 2
    I have tested the Code Sample and it **does not work(No location updates when device goes into doze)**. Anyone can force doze using adb and test it. ADB commands are `adb shell dumpsys battery unplug` and `adb shell dumpsys deviceidle force-idle` – VishalKale Sep 07 '17 at 11:29
  • Apps that have been running foreground services (with the associated notification) are not restricted by doze. – phnmnn Sep 07 '17 at 11:43
  • 3
    @VishalKale I reported the issue here: https://issuetracker.google.com/issues/63937937, Google seems to have acknowledged it's a bug but gave it a low priority for some reason... Wait and see :/ – Jukurrpa Sep 12 '17 at 19:28
  • @Jukurrpa Thanks for reporting it to Google. Starred it, lets see when they fix it. This bug persists in M & N as well. Since we are using Google play services FusedLocationProvider they might be able fix it for them as well. – VishalKale Sep 12 '17 at 19:44