Added in API level 1

LocationListener

interface LocationListener
android.location.LocationListener

Used for receiving notifications when the device location has changed. These methods are called when the listener has been registered with the LocationManager.

Summary

Public methods
open Unit
onFlushComplete(requestCode: Int)

Invoked when a flush operation is complete and after flushed locations have been delivered.

abstract Unit

Called when the location has changed.

open Unit

Called when the location has changed and locations are being delivered in batches.

open Unit

Called when the provider this listener is registered with becomes disabled.

open Unit

Called when a provider this listener is registered with becomes enabled.

open Unit
onStatusChanged(provider: String!, status: Int, extras: Bundle!)

This callback will never be invoked on Android Q and above, and providers can be considered as always in the LocationProvider#AVAILABLE state.

Public methods

onFlushComplete

Added in API level 31
open fun onFlushComplete(requestCode: Int): Unit

Invoked when a flush operation is complete and after flushed locations have been delivered.

Parameters
requestCode Int: the request code passed into LocationManager#requestFlush(String, LocationListener, int)

onLocationChanged

Added in API level 1
abstract fun onLocationChanged(location: Location): Unit

Called when the location has changed. A wakelock may be held on behalf on the listener for some brief amount of time as this callback executes. If this callback performs long running operations, it is the client's responsibility to obtain their own wakelock if necessary.

Parameters
location Location: the updated location This value cannot be null.

onLocationChanged

Added in API level 31
open fun onLocationChanged(locations: MutableList<Location!>): Unit

Called when the location has changed and locations are being delivered in batches. The default implementation calls through to onLocationChanged(android.location.Location) with all locations in the batch. The list of locations is always guaranteed to be non-empty, and is always guaranteed to be ordered from earliest location to latest location (so that the earliest location in the batch is at index 0 in the list, and the latest location in the batch is at index size-1 in the list).

Parameters
locations MutableList<Location!>: the location list This value cannot be null.

onProviderDisabled

Added in API level 1
open fun onProviderDisabled(provider: String): Unit

Called when the provider this listener is registered with becomes disabled. If a provider is disabled when this listener is registered, this callback will be invoked immediately.

Note that this method only has a default implementation on Android R and above, and this method must still be overridden in order to run successfully on Android versions below R. LocationListenerCompat from the compat libraries may be used to avoid the need to override for older platforms.

Parameters
provider String: the name of the location provider This value cannot be null.

onProviderEnabled

Added in API level 1
open fun onProviderEnabled(provider: String): Unit

Called when a provider this listener is registered with becomes enabled.

Note that this method only has a default implementation on Android R and above, and this method must still be overridden in order to run successfully on Android versions below R. LocationListenerCompat from the compat libraries may be used to avoid the need to override for older platforms.

Parameters
provider String: the name of the location provider This value cannot be null.

onStatusChanged

Added in API level 1
Deprecated in API level 29
open fun onStatusChanged(
    provider: String!,
    status: Int,
    extras: Bundle!
): Unit

Deprecated: This callback will never be invoked on Android Q and above.

This callback will never be invoked on Android Q and above, and providers can be considered as always in the LocationProvider#AVAILABLE state.

Note that this method only has a default implementation on Android R and above, and this method must still be overridden in order to run successfully on Android versions below R. LocationListenerCompat from the compat libraries may be used to avoid the need to override for older platforms.