| java.lang.Object | ||
| android.location.LocationManager | ||
This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location.
You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.LOCATION_SERVICE).
| LocationManager(ILocationManager service, Handler handler) |
| void | addProximityAlert(double latitude, double longitude, float radius, long expiration, Intent intent) | ||||
| Sets a proximity alert for the location given by the position (latitude, longitude) and the given radius. | |||||
| LocationProvider | getBestProvider(Criteria criteria) | ||||
| Returns the provider that best meets the given criteria. | |||||
| Location | getCurrentLocation(String provider) | ||||
| Returns a new location fix from the given provider. | |||||
| Location | getLastKnownLocation(String provider) | ||||
| Returns a Location indicating the data from the last known location fix obtained from the given provider. | |||||
| LocationProvider | getProvider(String name) | ||||
| Returns the location provider with the given name, or null if no provider exists by that name. | |||||
| int | getProviderStatus(String provider) | ||||
| Returns a information on the status of the given provider. | |||||
| List | getProviders() | ||||
| Returns a list of location providers. | |||||
| List | getProviders(Criteria criteria) | ||||
| Returns a list of LocationProviders that satisfy the given criteria, or null if none do. | |||||
| void | removeProximityAlert(Intent intent) | ||||
| Removes the proximity alert with the given intent. | |||||
| void | removeUpdates(Intent intent) | ||||
| Removes any current registration of the current activity with the given Intent. | |||||
| void | requestUpdates(LocationProvider provider, long minTime, float minDistance, Intent intent) | ||||
| Registers the current activity to be notified periodically by the named provider. | |||||
| void | requestUpdates(Criteria criteria, long minTime, float minDistance, Intent intent) | ||||
| Registers the current activity to be notified periodically by a provider meeting the given criteria for accuracy, power usage, etc. | |||||
Methods inherited
from class
java.lang.Object
The intent will have an extra added with key "entering" and a boolean value. If the value is true, the device is entering the proximity region; if false, it is exiting.
Due to the approximate nature of position estimation, if the device passes through the given area briefly, it is possible that no Intent will be fired. Similarly, an Intent could be fired if the device passes very close to the given area but does not actually enter it.
After the number of milliseconds given by the expiration parameter, the location manager will delete this proximity alert and no longer monitor it. A value of -1 indicates that there should be no expiration time.
Internally, a number of providers may be used in order to minimize battery usage. Only providers for which there are valid permissions will be used.
| latitude | the latitude of the central point of the alert region |
|---|---|
| longitude | the longitude of the central point of the alert region |
| radius | the radius of the central point of the alert region, in meters |
| expiration | time for this proximity alert, in milliseconds, or -1 to indicate no expiration |
| intent | the Intent to fire when entry to the alert region is detected |
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|---|
| SecurityException | if no permission exists for the required providers. |
Note that the requirement on monetary cost is not removed in this process.
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|---|
| SecurityException | if the provider is "gps" and the permission android.permission.ACCESS_GPS is not granted. |
| SecurityException | if the provider is "agps" and the permission android.permission.ACCESS_ASSISTED_GPS is not granted. |
| SecurityException | if the provider is "cell" and the permission android.permission.ACCESS_CELL_ID is not granted. |
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|---|
| SecurityException | if the provider is "gps" and the permission android.permission.ACCESS_GPS is not granted. |
| SecurityException | if the provider is "agps" and the permission android.permission.ACCESS_ASSISTED_GPS is not granted. |
| SecurityException | if the provider is "cell" and the permission android.permission.ACCESS_CELL_ID is not granted. |
| name | the provider name |
|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
| provider | a provider name |
|---|
| IllegalArgumentException | if the provider is unknown |
|---|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
| SecurityException | if the provider is "gps" and the permission android.permission.ACCESS_GPS is not granted. |
| SecurityException | if the provider is "agps" and the permission android.permission.ACCESS_ASSISTED_GPS is not granted. |
| SecurityException | if the provider is "cell" and the permission android.permission.ACCESS_CELL_ID is not granted. |
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime milliseconds have elapsed since the last update and the position has changed by minDistance meters, a new notification may be provided. To obtain notifications as frequently as possible, set both parameters to 0.
| provider | the provider with which to register |
|---|---|
| minTime | the minimum time interval for notifications, in milliseconds |
| minDistance | the minimum distance interval for notifications, in meters |
| intent | an intent to be fired for each location update |
| IllegalArgumentException | if provider is null |
|---|---|
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
| SecurityException | if the provider is "gps" and the permission android.permission.ACCESS_GPS is not granted. |
| SecurityException | if the provider is "agps" and the permission android.permission.ACCESS_ASSISTED_GPS is not granted. |
| SecurityException | if the provider is "cell" and the permission android.permission.ACCESS_CELL_ID is not granted. |
Periodically, an Intent will be fired. The fired Intent will be equivalent to the provided Intent in the sense of the Intent.filterEquals() method. The location data may be retrieved from the fired Intent as a Location object by calling intent.getExtra("location").
The frequency of notification may be controlled using the minTime and minDistance parameters. If either minTime milliseconds have elapsed since the last update, or the position has changed by minDistance meters, a new notification may be provided. To obtain notifications as frequently as possible, set both parameters to 0.
| criteria | Criteria the criteria required for the provider |
|---|---|
| minTime | the minimum time interval for notifications, in milliseconds |
| minDistance | the minimum distance interval for notifications, in meters |
| intent | an Intent to be fired for each location update |
| SecurityException | if the permission android.permission.ACCESS_LOCATION is not granted. |
|---|---|
| SecurityException | if no permitted providers are found. |