Hi sheik,
Please see below code. And you can see reference.
http://developer.android.com/reference/android/location/LocationListener.html
1. Implement LocationListener interface.
2. Get Location Manager.
3. Register LocationListener to LocationManager.
LocationListener.onLocationChanged(Location location) method is called
when GPS can receive location.
You can set minimum interval time or distance to work GPS on
requestLocationUpdates method.
Attention, if LocationListener is once registered, GPS will be being
activated basically.
You should call to LocationManager.removeUpdates at onDestroy or onStop.
Good luck,
Keiji
-----------------------------------------------------------------------
public class GPSActivity extends Activity {
// LocationManager
private LocationManager _mLocMan;
// LocationListener Interface
private final LocationListener _mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// implement here
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}; // _mLocationListener
@Override
public void onCreate(Bundle savedInstanceState) {
// get Location Manager
_mLocMan
= (LocationManager)this.getSystemService(LOCATION_SERVICE);
// register location listener
_mLocMan.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
_mLocationListener);
} // onCreate
@Override
public void onDestroy() {
// unregister location listener
_mLocMan.removeUpdates(_mLocationListener);
} // onDestroy
} // GPSActivity
-----------------------------------------------------------------------
sheik wrote:
> Hi,
> i need to know about the LocationListener() working in the Android
> DEV Phone(ADP1)
>
> Does it expect the user(device) to move in order to update the
> current location details or it automatically updates when ever the gps
> is enabled?
>
> Another query is regarding the getLastKnownLocation().....
>
> When is that last known location will be lost and thus returns null...
> (ADP1)...
>
> Thanks,
> regards,
> sheik
> >
>
--
Keiji,
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---