Google recommends using FusedLocationProviderClient
instead of LocationManager
Using LocationManager
I could subscribe to change status events of providers by using LocationListener
interface:
void onProviderEnabled(@NonNull String provider) {}
void onProviderDisabled(@NonNull String provider) {}
How can I do it using FusedLocationProviderClient
?
So answer my own question.
For FusedLocationProviderClient
we use LocationCallback
in which we have the next method which we can use together with LocationManager
to get status of providers
override fun onLocationAvailability(LocationAvailability: LocationAvailability?) {
super.onLocationAvailability(LocationAvailability)
val isGpsProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
val isNetProviderEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
}