2013-12-13 52 views

回答

1

的的LocationManager,並持有這些信息:

LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
boolean isNetworkdEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
0

我使用下面的代碼來檢查,如果用戶擁有GPS定位或啓用網絡提供商:

private static LocationManager sLocationManager = 
    (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 

public static boolean isLocationProviderEnabled() { 
    if (sLocationManager != null) { 
     boolean gpsEnabled = false; 
     boolean networkEnabled = false; 

     try { 
      gpsEnabled = sLocationManager 
        .isProviderEnabled(LocationManager.GPS_PROVIDER); 
      networkEnabled = sLocationManager 
        .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

      if (gpsEnabled || networkEnabled) { 
       return true; 
      } 
     } catch (Exception e) { 
     } 
    } 

    return false; 
}