I'm using a location service in the background using Fused Location Provider, it returns "fused" when I call the method getProvider() instead of Network or GPS. Is there a way I can get the provider from this?
I know that using LocationManager with GPS location I can get GPS or Network, but the listener gets killed when I try to use it in a background service.
Here is part of my code inside the onCreate method
locationRequest = new LocationRequest();
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(5000);
locationRequest.setSmallestDisplacement(3);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
this.locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Location currentLocation = locationResult.getLastLocation();
Log.d("currentProvider", currentLocation.getProvider());
}
};
this.mFusedLocationClient = LocationServices.getFusedLocationProviderClient(MyApplication.getAppContext());
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
} else {
this.mFusedLocationClient.requestLocationUpdates(this.locationRequest,
this.locationCallback, Looper.myLooper());
}
Is there a way I can get the provider from this?
You are. It is the fused provider. The locations provided by the fused provider are computed based not only on the GPS and network providers but other data sources as well, using proprietary algorithms.