Oreo: How To Catch Location Update From The Background?
I migrate my app to oreo (as it's requiered by google play now), and i have now an error when i start my phone : Not allowed to start service Intent My app is listening in backg
Solution 1:
Starting in Android Oreo you cannot simply start a background service while the app is in the background.
You can start your service as foreground service like that (Kotlin, but similar in Java):
val serviceIntent = Intent(context, LocationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
}
In your service make sure you call startForeground as soon as possible. This will also issue a notification so that the user knows your app is active in the background.
As Anis BEN NSIR has pointed out in the comments, you will probably also be affected by the new background location limits.
There is a nice article about Oreo's background exexution limits.
Post a Comment for "Oreo: How To Catch Location Update From The Background?"