Android SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission. 错误

Android targetSdkVersion 版本升至 26

在AndroidManifest.xml中加入了以下的权限:


也已经按照网上方法进行了动态权限请求:

`if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(activity,
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(activity,
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
android.Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
} else {
}

但是仍然会报错。

解决方式:
1.确认是 android.Manifest.permission.ACCESS_COARSE_LOCATION 而不是Manifest.permission.ACCESS_COARSE_LOCATION
2.请求获取权限时应该为:

requestPermissions(new String[]{ android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);

你可能感兴趣的:(填坑之路)