我正在更新我的应用程序以使用新的 Android Marshmallow 权限框架,看起来用户在运行时授予 ACCESS_FINE_LOCATION 权限就足以使应用程序正常工作。这就是我所做的:
public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };
public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
再往下看:
public static boolean checkConnectionPermission(final Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
if (context.checkSelfPermission(permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return true;
}
else {
((Activity) context).requestPermissions(runtimePermissions,
LOCATION_PERMISSION_IDENTIFIER);
return false;
}
}
// since in API levels below M the permission is granted on
// installation,
// it is considered a given that the permission has been granted since
// the
// app is running. So we return true by default
else {
return true;
}
}
我只是担心我忽略了一些可能在未来(应用程序接近生产)导致安全异常的问题。
我想我的最终问题是:授予 FINE_LOCATION 是否也会以某种方式自动授予 COARSE_LOCATION?
最佳答案
这里已经回答过了。
If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?
一些额外的信息,你应该看看权限组。
https://developer.android.com/preview/features/runtime-permissions.html
它们在同一个权限组中。如果你真的想安全起见,只需将两者都包含在你的 list 中,并在需要时请求它们。这对用户来说是透明的。
关于android - 如果用户已经授予 ACCESS_FINE_LOCATION,是否需要 ACCESS_COARSE_LOCATION?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305580/