So, with Android O, you need to have your service running as a foreground service if you want to receive more than just a few location updates per hour.
I noticed that the old method for starting a foreground service does seem to work on O. i.e.
startForeground(NOTIFICATION_ID, getNotification());
According to the behaviour changes guide here: https://developer.android.com/preview/behavior-changes.html
The NotificationManager.startServiceInForeground() method starts a foreground service. The old way to start a foreground service no longer works.
Though the new method only works when targeting O, it seems that the old method still seems to work on an O device whether targeting O or not.
Edit Including example:
The Google sample project LocationUpdatesForegroundService actually has a working example where you can see the issue first hand. https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService
The startForeground method seems to work without issue whether targeting and compiling against API level 25 OR targeting and compiling against O (as directed to here: https://developer.android.com/preview/migration.html#uya)
So, to reproduce:
- Configure the app gradle as mentioned in the previous link
- Open the app
- Request location updates
- Close app (either via back button or home button)
Service is running in foreground (shown by icon in notification shade). Location updates are coming through as expected (every 10 seconds) even on a device running O. What I am missing here?