正如@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());
GPSLocationListener类:
private class GPSLocationListener implements LocationListener,
GpsStatus.Listener {
private boolean isGPSFix;
public void onGpsStatusChanged(int event) {
checkGlonassFeature(); // the method which checks if locations from GLONASS or GPS
switch (event) {
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
if (mLastLocation != null)
isGPSFix = (SystemClock.elapsedRealtime() - lastGPStime) < 3000;
if (isGPSFix) { // A fix has been acquired.
Toast toast = Toast.makeText(GPSLocationService.this, "GPS has a fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else { // The fix has been lost.
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) {
// Do works here
}
@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();
}
}
请注意,它只是对上述答案的补充。
祝你好运。