Stay organized with collections
Save and categorize content based on your preferences.
LocationListener
public
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.
Developer Guides
For more information about identifying user location, read the
Obtaining User
Location developer guide.
Summary
Public methods |
default
void
|
onFlushComplete(int requestCode)
Invoked when a flush operation is complete and after flushed locations have been delivered.
|
default
void
|
onLocationChanged(List<Location> locations)
Called when the location has changed and locations are being delivered in batches.
|
abstract
void
|
onLocationChanged(Location location)
Called when the location has changed.
|
default
void
|
onProviderDisabled(String provider)
Called when the provider this listener is registered with becomes disabled.
|
default
void
|
onProviderEnabled(String provider)
Called when a provider this listener is registered with becomes enabled.
|
default
void
|
onStatusChanged(String provider, int status, Bundle extras)
This method was deprecated
in API level 29.
This callback will never be invoked on Android Q and above.
|
Public methods
onFlushComplete
public void onFlushComplete (int requestCode)
Invoked when a flush operation is complete and after flushed locations have been delivered.
onLocationChanged
public void onLocationChanged (List<Location> locations)
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 |
List : the location list
This value cannot be null . |
onLocationChanged
public abstract void onLocationChanged (Location location)
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 . |
onProviderDisabled
public void onProviderDisabled (String provider)
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
public void onProviderEnabled (String provider)
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
public void onStatusChanged (String provider,
int status,
Bundle extras)
This method was deprecated
in API level 29.
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.
Parameters |
provider |
String |
status |
int |
extras |
Bundle |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# LocationListener\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nLocationListener\n================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/location/LocationListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nLocationListener\n`\n\n\n`\n\n\n`\n\n|-----------------------------------|\n| android.location.LocationListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nUsed for receiving notifications when the device location has changed. These methods are called\nwhen the listener has been registered with the LocationManager.\n\n### Developer Guides\n\nFor more information about identifying user location, read the\n[Obtaining User\nLocation](/guide/topics/location/obtaining-user-location) developer guide.\n\n\u003cbr /\u003e\n\n**See also:**\n\n- [LocationManager.requestLocationUpdates(String, LocationRequest, Executor, LocationListener)](/reference/android/location/LocationManager#requestLocationUpdates(java.lang.String,%20android.location.LocationRequest,%20java.util.concurrent.Executor,%20android.location.LocationListener))\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` default void` | ` `[onFlushComplete](/reference/android/location/LocationListener#onFlushComplete(int))`(int requestCode) ` Invoked when a flush operation is complete and after flushed locations have been delivered. |\n| ` default void` | ` `[onLocationChanged](/reference/android/location/LocationListener#onLocationChanged(java.util.List\u003candroid.location.Location\u003e))`(`[List](/reference/java/util/List)`\u003c`[Location](/reference/android/location/Location)`\u003e locations) ` Called when the location has changed and locations are being delivered in batches. |\n| ` abstract void` | ` `[onLocationChanged](/reference/android/location/LocationListener#onLocationChanged(android.location.Location))`(`[Location](/reference/android/location/Location)` location) ` Called when the location has changed. |\n| ` default void` | ` `[onProviderDisabled](/reference/android/location/LocationListener#onProviderDisabled(java.lang.String))`(`[String](/reference/java/lang/String)` provider) ` Called when the provider this listener is registered with becomes disabled. |\n| ` default void` | ` `[onProviderEnabled](/reference/android/location/LocationListener#onProviderEnabled(java.lang.String))`(`[String](/reference/java/lang/String)` provider) ` Called when a provider this listener is registered with becomes enabled. |\n| ` default void` | ` `[onStatusChanged](/reference/android/location/LocationListener#onStatusChanged(java.lang.String,%20int,%20android.os.Bundle))`(`[String](/reference/java/lang/String)` provider, int status, `[Bundle](/reference/android/os/Bundle)` extras) ` *This method was deprecated in API level 29. This callback will never be invoked on Android Q and above.* |\n\nPublic methods\n--------------\n\n### onFlushComplete\n\nAdded in [API level 31](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void onFlushComplete (int requestCode)\n```\n\nInvoked when a flush operation is complete and after flushed locations have been delivered.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `requestCode` | `int`: the request code passed into [LocationManager.requestFlush(String, LocationListener, int)](/reference/android/location/LocationManager#requestFlush(java.lang.String,%20android.location.LocationListener,%20int)) \u003cbr /\u003e |\n\n### onLocationChanged\n\nAdded in [API level 31](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void onLocationChanged (List\u003cLocation\u003e locations)\n```\n\nCalled when the location has changed and locations are being delivered in batches. The\ndefault implementation calls through to [onLocationChanged(android.location.Location)](/reference/android/location/LocationListener#onLocationChanged(android.location.Location)) with all\nlocations in the batch. The list of locations is always guaranteed to be non-empty, and is\nalways guaranteed to be ordered from earliest location to latest location (so that the\nearliest location in the batch is at index 0 in the list, and the latest location in the\nbatch is at index size-1 in the list).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------------|---------------------------------------------------------------|\n| `locations` | `List`: the location list This value cannot be `null`. \u003cbr /\u003e |\n\n**See also:**\n\n- [LocationRequest.getMaxUpdateDelayMillis()](/reference/android/location/LocationRequest#getMaxUpdateDelayMillis()) \n\n### onLocationChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onLocationChanged (Location location)\n```\n\nCalled when the location has changed. A wakelock may be held on behalf on the listener for\nsome brief amount of time as this callback executes. If this callback performs long running\noperations, it is the client's responsibility to obtain their own wakelock if necessary.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|----------------------------------------------------------------------|\n| `location` | `Location`: the updated location This value cannot be `null`. \u003cbr /\u003e |\n\n### onProviderDisabled\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void onProviderDisabled (String provider)\n```\n\nCalled when the provider this listener is registered with becomes disabled. If a provider is\ndisabled when this listener is registered, this callback will be invoked immediately.\n\nNote that this method only has a default implementation on Android R and\nabove, and this method must still be overridden in order to run successfully on Android\nversions below R. LocationListenerCompat from the compat libraries may be used to avoid the\nneed to override for older platforms.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|---------------------------------------------------------------------------------|\n| `provider` | `String`: the name of the location provider This value cannot be `null`. \u003cbr /\u003e |\n\n### onProviderEnabled\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void onProviderEnabled (String provider)\n```\n\nCalled when a provider this listener is registered with becomes enabled.\n\nNote that this method only has a default implementation on Android R and\nabove, and this method must still be overridden in order to run successfully on Android\nversions below R. LocationListenerCompat from the compat libraries may be used to avoid the\nneed to override for older platforms.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|---------------------------------------------------------------------------------|\n| `provider` | `String`: the name of the location provider This value cannot be `null`. \u003cbr /\u003e |\n\n### onStatusChanged\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nDeprecated in [API level\n29](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void onStatusChanged (String provider, \n int status, \n Bundle extras)\n```\n\n\n**This method was deprecated\nin API level 29.** \n\nThis callback will never be invoked on Android Q and above.\n\nThis callback will never be invoked on Android Q and above, and providers can be considered\nas always in the [LocationProvider.AVAILABLE](/reference/android/location/LocationProvider#AVAILABLE) state.\n\nNote that this method only has a default implementation on Android R and\nabove, and this method must still be overridden in order to run successfully on Android\nversions below R. LocationListenerCompat from the compat libraries may be used to avoid the\nneed to override for older platforms.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------|\n| `provider` | `String` \u003cbr /\u003e |\n| `status` | `int` \u003cbr /\u003e |\n| `extras` | `Bundle` \u003cbr /\u003e |"]]