Google is committed to advancing racial equity for Black communities. See how.

LocationManagerCompat

public final class LocationManagerCompat
extends Object

java.lang.Object
   ↳ androidx.core.location.LocationManagerCompat


Helper for accessing features in LocationManager.

Summary

Public methods

static boolean isLocationEnabled(LocationManager locationManager)

Returns the current enabled/disabled state of location.

static boolean registerGnssStatusCallback(LocationManager locationManager, GnssStatusCompat.Callback callback, Handler handler)

Registers a platform agnostic GnssStatusCompat.Callback.

static boolean registerGnssStatusCallback(LocationManager locationManager, Executor executor, GnssStatusCompat.Callback callback)

Registers a platform agnostic GnssStatusCompat.Callback.

static void unregisterGnssStatusCallback(LocationManager locationManager, GnssStatusCompat.Callback callback)

Unregisters a platform agnostic GnssStatusCompat.Callback.

Inherited methods

Public methods

isLocationEnabled

public static boolean isLocationEnabled (LocationManager locationManager)

Returns the current enabled/disabled state of location.

Parameters
locationManager LocationManager

Returns
boolean true if location is enabled and false if location is disabled.

registerGnssStatusCallback

public static boolean registerGnssStatusCallback (LocationManager locationManager, 
                GnssStatusCompat.Callback callback, 
                Handler handler)

Registers a platform agnostic GnssStatusCompat.Callback. See LocationManager.addGpsStatusListener(GpsStatus.Listener) and LocationManager.registerGnssStatusCallback(GnssStatus.Callback, Handler).

Requires the ACCESS_FINE_LOCATION permission.

Parameters
locationManager LocationManager

callback GnssStatusCompat.Callback

handler Handler

Returns
boolean

registerGnssStatusCallback

public static boolean registerGnssStatusCallback (LocationManager locationManager, 
                Executor executor, 
                GnssStatusCompat.Callback callback)

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.

Requires the ACCESS_FINE_LOCATION permission.

Parameters
locationManager LocationManager

executor Executor

callback GnssStatusCompat.Callback

Returns
boolean

Throws
IllegalStateException on Android M or below, if the current Looper or main Looper is blocked by the thread this function is invoked on

unregisterGnssStatusCallback

public static void unregisterGnssStatusCallback (LocationManager locationManager, 
                GnssStatusCompat.Callback callback)

Unregisters a platform agnostic GnssStatusCompat.Callback. See LocationManager.removeGpsStatusListener(GpsStatus.Listener) and LocationManager.unregisterGnssStatusCallback(GnssStatus.Callback).

Parameters
locationManager LocationManager

callback GnssStatusCompat.Callback