@DavidWasser, . @DavidWasser.
LocationManager:
private LocationManager locationManager;
:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
implements LocationListener, GpsStatus.Listener:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new GPSLocationListener());
GPSLocationListenerClass:
private class GPSLocationListener implements LocationListener,
GpsStatus.Listener {
private boolean isGPSFix;
public void onGpsStatusChanged(int event) {
checkGlonassFeature();
switch (event) {
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
if (mLastLocation != null)
isGPSFix = (SystemClock.elapsedRealtime() - lastGPStime) < 3000;
if (isGPSFix) {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS has a fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS DOES NOT have a fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
Toast toast = Toast.makeText(GPSLocationService.this, "GPS got first fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
isGPSFix = true;
break;
}
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
String statusDescription = "unknown";
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
statusDescription = "OUT_OF_SERVICE";
break;
case LocationProvider.AVAILABLE:
statusDescription = "AVAILABLE";
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
statusDescription = "TEMPORARILY_UNAVAILABLE";
break;
}
}
@Override
public void onProviderEnabled(String provider) {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS feature is active", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
@Override
public void onProviderDisabled(String provider) {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS feature is passive", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
, , :
public void checkGlonassFeature() {
boolean isGPSFromGlonass = false;
final GpsStatus gs = this.locationManager.getGpsStatus(null);
final Iterable<GpsSatellite> it = gs.getSatellites();
for (GpsSatellite sat : it) {
if(sat.usedInFix()){
if(sat.getPrn() > 65 && sat.getPrn() < 88)
isGPSFromGlonass = true;
else
isGPSFromGlonass = false;
}
else
isGPSFromGlonass = false;
}
if(isGPSFromGlonass){
Toast toast = Toast.makeText(getBaseContext(), "Location from GLONASS", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
else{
Toast toast = Toast.makeText(getBaseContext(), "Location from GPS", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
, .
.