这段代码在其他手机上运行良好,在三星 Galaxy s3 和 android 4.0.3 上也能正常运行,但在三星 Galaxy S3 和 android 4.1.1 上运行不正常,知道吗?
问题是永远不会调用 onLocationChanged 方法。
返回的提供者是“网络”
/**
* @see android.app.Application#onCreate()
*/
@Override
public void onCreate() {
locationManager = (LocationManager) this.getSystemService(getApplicationContext().LOCATION_SERVICE);
String provider = getLocationProvider();
locationManager.requestLocationUpdates(provider, 0, 20, locationListener);
}
/**
* @see android.location.LocationListener
*/
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
currentLocationUser = location;
if (onLocationListener != null) {
onLocationListener.onLocationChanged(location);
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
public String getLocationProvider() {
Criteria locationCriteria = new Criteria();
locationCriteria.setAccuracy();
return locationManager.getBestProvider(locationCriteria, true);
}