After much testing on GPS, I found a solution. When the Android application calls the location manager and the GPS starts searching, one event is triggered, and when the gps lock is blocked, another event is triggered. The following code shows how to do this.
locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (isGPSEnabled) {
if (locationManager != null) {
locationManager.addGpsStatusListener(mGPSStatusListener);
gpslocationListener = new LocationListener() {
public void onLocationChanged(Location loc) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES_GPS, MIN_DISTANCE_CHANGE_FOR_UPDATES_GPS,
gpslocationListener);
}
}
/* * GPSListener, , * GPS , GPS , GPS */
public Listener mGPSStatusListener = new GpsStatus.Listener() {
public void onGpsStatusChanged(int event) {
switch(event) {
case GpsStatus.GPS_EVENT_STARTED:
Toast.makeText(mContext, "GPS_SEARCHING", Toast.LENGTH_SHORT).show();
System.out.println("TAG - GPS searching: ");
break;
case GpsStatus.GPS_EVENT_STOPPED:
System.out.println("TAG - GPS Stopped");
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
Toast.makeText(mContext, "GPS_LOCKED", Toast.LENGTH_SHORT).show();
Location gpslocation = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(gpslocation != null) {
System.out.println("GPS Info:"+gpslocation.getLatitude()+":"+gpslocation.getLongitude());
locationManager.removeGpsStatusListener(mGPSStatusListener);
}
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
break;
}
}
};
GPS- GPS.
, GPS, GPSStatus. GPS_SEARCHING , GPS , GPS_LOCKED , GPS . GPS, GPS_EVENT_FIRST_FIX , ( GPS_LOCKED), GPS , GPS_SEARCHING (.. GPS_STARTED ). GPS_EVENT_FIRST_FIX GPSstatus.
GPS_EVENT_FIRST_FIX, gpslastknownlocation(), GPS-. ( Android).
, ...