murmur
112 天前
private String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
String provider = highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
if (!locationManager.isProviderEnabled(provider)) {
provider = provider.equals(LocationManager.GPS_PROVIDER) ? LocationManager.NETWORK_PROVIDER : LocationManager.GPS_PROVIDER;
if (!locationManager.isProviderEnabled(provider)) {
return null;
}
}
// If it's an enabled provider, but we don't have permissions, ignore it
boolean finePermission = PermissionHelper.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
boolean coarsePermission = PermissionHelper.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
if (provider.equals(LocationManager.GPS_PROVIDER) && !finePermission && !coarsePermission) {
return null;
}
return provider;
}
这是我用的方法