0

my app is showing the location long and lat and it is working well

but when i have to detect the location sensor status like on , of , working , error,... it have some problem

my idea was this code :

  Case LocationSensor1.Sensor.State of
        TSensorState.Added : label5.Text:='2';
        TSensorState.Removed : label5.Text:='3';
        TSensorState.Initializing : label5.Text:='4';
        TSensorState.Ready : label5.Text:='ready';
        TSensorState.NoData : label5.Text:='6';
        TSensorState.AccessDenied : label5.Text:='7';
        TSensorState.Error : label5.Text:='8';
        else label5.Text:='error';
  End;

but when i turn on or off the gps it is ready every time

how can i detect and show the gps sensor status ?

peiman F.
  • 1,648
  • 1
  • 19
  • 42

1 Answers1

0

You have to create a class extending the LocationListener class. You will be notified of the GPS status changes by two callback functions : onProviderEnabled, which will be called when the GPS is enabled, and onProviderDisabled when it is disabled.

To register your listener, use ((LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE)).requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, myLocationListener); .

Zelig63
  • 1,592
  • 1
  • 23
  • 40
  • where this class must register? i have to know the current status of location sensor,maybe user activated the gps before run my app ?!! – peiman F. Sep 10 '17 at 06:29
  • Your app needs to listen, so that's where the listener must be registered...If the GPS is already on, location changes will be provided to you in the `OnLocationChanged`callback function. – Zelig63 Sep 10 '17 at 13:35
  • Or you should use the `GpsStatus.Listener` class. – Zelig63 Sep 10 '17 at 13:45