1
我使用三星手機通過LocationManager API獲取位置,如果GPS禁用,我無法獲取位置,通過網絡提供商我無法獲取位置。如果GPS被禁用,位置沒有進入三星手機
這裏是代碼,這在HTC & sony甚至停用GPS,但不在三星手機。
public Location getLocation() {
try {
mLocationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = mLocationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = mLocationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER); //fails in samsung phone returns NULL
if (isGPSEnabled == false && isNetworkEnabled == false) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
mLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (mLocationManager != null) {
mLocation = mLocationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (mLocation == null) {
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (mLocationManager != null) {
mLocation = mLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return mLocation;
}
之前運行下面的代碼啓用你的網絡供應商? – Rajeev
嗨,是它啓用 – Naruto