LocationManagerCompat
class LocationManagerCompat
kotlin.Any | |
↳ | androidx.core.location.LocationManagerCompat |
Helper for accessing features in LocationManager
.
Summary
Public methods | |
---|---|
static Boolean |
isLocationEnabled(@NonNull locationManager: LocationManager) Returns the current enabled/disabled state of location. |
static Boolean |
registerGnssStatusCallback(@NonNull locationManager: LocationManager, @NonNull callback: GnssStatusCompat.Callback, @NonNull handler: Handler) Registers a platform agnostic |
static Boolean |
registerGnssStatusCallback(@NonNull locationManager: LocationManager, @NonNull executor: Executor, @NonNull callback: GnssStatusCompat.Callback) Registers a platform agnostic |
static Unit |
unregisterGnssStatusCallback(@NonNull locationManager: LocationManager, @NonNull callback: GnssStatusCompat.Callback) Unregisters a platform agnostic |
Public methods
isLocationEnabled
static fun isLocationEnabled(@NonNull locationManager: LocationManager): Boolean
Returns the current enabled/disabled state of location.
Return | |
---|---|
Boolean |
true if location is enabled and false if location is disabled. |
registerGnssStatusCallback
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION") static fun registerGnssStatusCallback(
@NonNull locationManager: LocationManager,
@NonNull callback: GnssStatusCompat.Callback,
@NonNull handler: Handler
): Boolean
Registers a platform agnostic GnssStatusCompat.Callback
. See LocationManager#addGpsStatusListener(GpsStatus.Listener)
and LocationManager#registerGnssStatusCallback(GnssStatus.Callback, Handler)
.
registerGnssStatusCallback
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION") static fun registerGnssStatusCallback(
@NonNull locationManager: LocationManager,
@NonNull executor: Executor,
@NonNull callback: GnssStatusCompat.Callback
): Boolean
Registers a platform agnostic GnssStatusCompat.Callback
. See LocationManager#addGpsStatusListener(GpsStatus.Listener)
and LocationManager#registerGnssStatusCallback(Executor, GnssStatus.Callback)
.
Internally, this API will always utilize GnssStatus APIs and instances on Android N and above, and will always utilize GpsStatus APIs and instances below Android N. Callbacks will always occur on the given executor.
If invoked on Android M or below, this will result in GpsStatus registration being run on either the current Looper or main Looper. If the thread this function is invoked on is different from that Looper, the caller must ensure that the Looper thread cannot be blocked by the thread this function is invoked on. The easiest way to avoid this is to ensure this function is invoked on a Looper thread.
Exceptions | |
---|---|
IllegalStateException |
on Android M or below, if the current Looper or main Looper is blocked by the thread this function is invoked on |
unregisterGnssStatusCallback
static fun unregisterGnssStatusCallback(
@NonNull locationManager: LocationManager,
@NonNull callback: GnssStatusCompat.Callback
): Unit
Unregisters a platform agnostic GnssStatusCompat.Callback
. See LocationManager#removeGpsStatusListener(GpsStatus.Listener)
and LocationManager#unregisterGnssStatusCallback(GnssStatus.Callback)
.