public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener, Looper looper)
Records current activity that will be periodically notified by the specified provider. A periodically supplied LocationListener will be called with the current location or with a status update.
It may take some time to get the latest location. If an immediate location is required, applications can use the getLastKnownLocation (String) method.
If the provider is disabled by the user, updates will stop and the onProviderDisabled(String) method will be called. As soon as the provider turns on again, the onProviderEnabled (String) method will be called and location updates will start again.
The notification frequency can be controlled using the minTime and minDistance . If minTime greater than 0, the LocationManager can potentially take a rest in minTime milliseconds between location updates to conserve power. If minDistance greater than 0, the location will be broadcast only if the device moves minDistance meters. To receive notifications as often as possible, set both parameters to 0.
Background services should be careful when setting a sufficiently high minTime so that the device does not consume too much power while constantly supporting GPS or wireless radios. In particular, values โโless than 60,000 m are not recommended.
The supplied Looper is used to implement a callback mechanism.
Parameters
- supplier name of the provider with which to register
- minTime minimum time interval for notifications, in milliseconds. This field is used only as a hint to save energy and the actual time between location updates may be greater or less than this value.
- min Distance minimum distance interval for notifications, in meters
- listener a whose onLocationChanged (Location) method will be called for each location update
- looper a Looper object whose message queue will be used to implement the callback mechanism.
Gives out
IllegalArgumentException if the provider is null or does not exist
IllegalArgumentException if the listener is null
IllegalArgumentException if looper is null
SecurityException if the provider does not have the appropriate permission.
source share