I'm using FusionLocationProviderClient to get the location update periodically in the background. It's working fine. But, Having some issue in Oreo. Location update stops as soon as application goes background.
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
mFusedLocationClient.requestLocationUpdates(createLocationRequest(), getPendingIntent(context)).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "Location update registered successfully");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.i(TAG, "Location update failed to register " + e);
}
});
private LocationRequest createLocationRequest() {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setMaxWaitTime(MAX_WAIT_TIME_IN_MILLISECONDS);
return mLocationRequest;
}