java-如何检查是否在Android 4.4及更高版本中以编程方式打开了gps?
作者:互联网
这个问题已经在这里有了答案: > How do I get the current GPS location programmatically in Android? 22个
我尝试过在线搜索答案,但它们似乎仅适用于Android 4.0及以下版本
解决方法:
public static boolean isLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}else{
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
标签:android-4-4-kitkat,gps,java,android 来源: https://codeday.me/bug/20191111/2019350.html