Reputation: 299
i want to call a method when the status of GPS become enabled. i have wrote this, but it doesn't work.
private LocationManager locManager;
private GpsStatus mStatus;
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locManager.addGpsStatusListener(this);
@Override
public void onGpsStatusChanged(int event)
{
mStatus = locManager.getGpsStatus(null);
switch (event) {
case GpsStatus.GPS_EVENT_STARTED:
myMethod1();
break;
case GpsStatus.GPS_EVENT_STOPPED:
myMethod2();
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
break;
}
}
can anyone help me?
Upvotes: 1
Views: 123
Reputation: 2082
You can detect status of GPS by following way.
Look at GpsStatus.Listener. Register it with locationManager.addGpsStatusListener(gpsStatusListener).
Also check this SO link for better understanding.
Upvotes: 0
Reputation: 13785
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
// GPS Enable
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
Upvotes: 1