0

Using PendingIntent.getService(...) has been the common way to request location updates. Can this still be used for apps running on O devices to receive background location updates?

Shailen Tuli
  • 13,815
  • 5
  • 40
  • 51

1 Answers1

0

Apps targeting N or lower (and running on an O or lower device) may use either PendingIntent.getService() or PendingIntent.getBroadcast() when calling [FusedLocationPRoviderApi#requestLocationUpdates](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi.html#requestLocationUpdates(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.location.LocationRequest, android.app.PendingIntent)).

Apps targeting O should only use PendingIntent.getBroadcast() (and define a BroadcastReceiver and register it in the manifest) in order to continue to receive location updates while in the background. This is because apps targeting O are subject to limits on services started in the background.

Apps targeting O can continue to use PendingIntent.getService() if it only needs to receive location updates while in the foreground.

Shailen Tuli
  • 13,815
  • 5
  • 40
  • 51
  • 1
    Why do you say that App targeting Android O should only use PendingIntent.getBroadcast()? Documentation says to use PendingIntent.getService() https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi.html#requestLocationUpdates(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.location.LocationRequest, android.app.PendingIntent) – NinjaCoder Oct 26 '17 at 01:46