Android 9 :Foreground Service with notification stops after phone goes to dozes mode

254 Views Asked by At

We are using location updates in constant intervals to provide our service using Foreground service. With Android 9 the service completely stops until user unlocks the screen. It is working fine in Android O and pre O devices. I turned to internet and tried to use all the work around available. But nothing seems to work. Any one is facing this issue ? Is there any solution ?

According to the docs , Foreground services with notifications are exempted from blocking. I have tried to use wake up lock and Alarm manager . Nothing worked so far. What am I missing ? There is no clear documentation nor Stack over flow answers this .

1

There are 1 best solutions below

0
rana On

In 26 and above You have to mention the foreground Service type as Location in the AndroidManifest

           <service
            android:name="LocationUpdatesService"
            android:enabled="true"
            android:exported="true"
            android:foregroundServiceType="location" />

And You have to call ContextCompat.startForegroundService(getApplicationContext(), intent); instead of just calling startService() as in Pre-O OS versions.