AndroidLocationProvider

A LocationProvider built on the LocationManager platform APIs.

Each collection selects a provider and request settings from LocationRequest, emits the last known location when one exists, and removes its listener when collection ends.

On Android 12 and newer, LocationAccuracy.BestForNavigation and LocationAccuracy.High map to LocationRequest.QUALITY_HIGH_ACCURACY, LocationAccuracy.Balanced maps to LocationRequest.QUALITY_BALANCED_POWER_ACCURACY, and LocationAccuracy.Low maps to LocationRequest.QUALITY_LOW_POWER. Earlier versions use the corresponding Criteria accuracy and power requirements. LocationAccuracy.Lowest uses LocationManager.PASSIVE_PROVIDER on every version.

A disabled location service or LocationListener.onProviderDisabled maps to LocationUnavailableReason.ServicesDisabled. A SecurityException maps to LocationUnavailableReason.PermissionDenied. An IllegalArgumentException while registering the selected provider maps to LocationUnavailableReason.UnexpectedFailure, because this provider constructs and validates every request argument itself.

permission and requestPermission delegate to an AndroidLocationPermissionRequester; see its documentation for when the system permission dialog can be shown.

Parameters

context

Context used to obtain the platform LocationManager.

requester

Permission requester that backs permission and requestPermission.

Constructors

Link copied to clipboard
constructor(context: Context)

Creates a provider with its own AndroidLocationPermissionRequester.

Properties

Link copied to clipboard

Whether this provider has a usable platform implementation.

Link copied to clipboard
open override val backendId: String

A stable implementation name for diagnostics, when the provider declares one.

Link copied to clipboard
open override val permission: StateFlow<LocationPermission>

Current foreground location permission.

Functions

Link copied to clipboard
open override fun requestPermission()

Starts a foreground permission request and returns immediately.

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
open override fun updates(request: LocationRequest): Flow<LocationEvent>

Returns a cold stream of foreground location updates.