如果用户已经授予 ACCESS_FINE_LOCATION,是否还需要 ACCESS_COARSE_LOCATION?
Is ACCESS_COARSE_LOCATION necessary if the user has already granted ACCESS_FINE_LOCATION?
我正在更新我的应用程序以使用新的 Android Marshmallow 权限框架,看起来用户在运行时授予 ACCESS_FINE_LOCATION 权限就足以使应用程序正常工作。这就是我所做的:
public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };
public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
再往下class:
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?
应用实际上可以注册两种类型的位置更新。细粒度,它使用全球定位系统使设备的位置精确到几米以内,而粗粒度,它使用设备可用的 Wifi、手机信号塔和其他数据来获得粗略的(精确到几十米) ) 设备的位置。
选择权在你。
这里已经回答过了。
If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?
一些额外的信息,你应该看看权限组。
https://developer.android.com/preview/features/runtime-permissions.html
他们在同一个权限组。如果你真的想安全起见,只需将两者都包含在你的清单中,并在需要时请求它们。它对用户是透明的。
根据 this blog post,如果您在清单中指定了两者并且用户已授予您一个,那么当您请求另一个时,它将被自动授予(因为它们都在同一个权限组)。
这意味着如果您已被授予 COARSE_LOCATION 然后请求 FINE_LOCATION 您可以在不提示用户的情况下获得它,但要注意的是您仍然必须在清单。
我正在更新我的应用程序以使用新的 Android Marshmallow 权限框架,看起来用户在运行时授予 ACCESS_FINE_LOCATION 权限就足以使应用程序正常工作。这就是我所做的:
public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };
public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
再往下class:
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?
应用实际上可以注册两种类型的位置更新。细粒度,它使用全球定位系统使设备的位置精确到几米以内,而粗粒度,它使用设备可用的 Wifi、手机信号塔和其他数据来获得粗略的(精确到几十米) ) 设备的位置。
选择权在你。
这里已经回答过了。
If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?
一些额外的信息,你应该看看权限组。
https://developer.android.com/preview/features/runtime-permissions.html
他们在同一个权限组。如果你真的想安全起见,只需将两者都包含在你的清单中,并在需要时请求它们。它对用户是透明的。
根据 this blog post,如果您在清单中指定了两者并且用户已授予您一个,那么当您请求另一个时,它将被自动授予(因为它们都在同一个权限组)。
这意味着如果您已被授予 COARSE_LOCATION 然后请求 FINE_LOCATION 您可以在不提示用户的情况下获得它,但要注意的是您仍然必须在清单。