Use Broadcast receiver to get location in version 8.0...i have test it was working for me
private PendingIntent getPendingIntent() {
// Note: for apps targeting API level 25 ("Nougat") or lower, either
// PendingIntent.getService() or PendingIntent.getBroadcast() may be used when requesting
// location updates. For apps targeting API level O, only
// PendingIntent.getBroadcast() should be used. This is due to the limits placed on services
// started in the background in "O".
// TODO(developer): uncomment to use PendingIntent.getService().
// Intent intent = new Intent(this, LocationUpdatesIntentService.class);
// intent.setAction(LocationUpdatesIntentService.ACTION_PROCESS_UPDATES);
// return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class);
intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES);
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Reference : https://github.com/googlesamples/android-play-location/blob/master/LocationUpdatesPendingIntent/app/src/main/java/com/google/android/gms/location/sample/locationupdatespendingintent/MainActivity.java
Note: Some of device is not working like OPPO,Vivo, due to security reason.. In this case you have to go to Security permissions
->
autostart
-> then enable autostart from there.