0

I am working in app where user location tracking all time and updated into server in background service, i update location to the server from onLocationChanged(Location location) @Override method. I want hit server when location is not changed also. is there any @Override method who is call when Gps is off?Mean,i want to notify the server that user's gps is off.

Suman
  • 1,307
  • 15
  • 32

1 Answers1

0

You can detect GPS on/off event/status with GpsStatus.Listener and register it with the LocationManager.

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.addGpsStatusListener(new android.location.GpsStatus.Listener()
{
    public void onGpsStatusChanged(int event)
    {
        switch(event)
        {
        case GPS_EVENT_STARTED:
            // do your tasks
            break;
        case GPS_EVENT_STOPPED:
            // do your tasks
            break;
        }
    }
});
USKMobility
  • 5,721
  • 2
  • 27
  • 34
  • thanks,for you contribution.but i want when gps off then fuesed location notify and then notify the server. – Suman May 21 '16 at 06:37
  • no override method available to detect the GPS is off. You try trick, onConnectionSuspended and onConnectionfailed and check your GPS is off then notify to the server. I think better to add GPS listener – USKMobility May 21 '16 at 06:51
  • thank you,but when called onConnectionSuspended and onConnectionfailed ?because when i off the Gps then it is not called.. – Suman May 21 '16 at 12:41