Android M 6.0权限问题

Android M 6.0 permissions issue

我有一个 Android M 应用程序 (targetSDK=23),它需要位置权限。当用户在 Moto X Play(纯版)设备上授予此权限时,应用 + 系统每次都会请求权限,即使用户已授予权限。我可以在系统提示出现和用户接受之前和之后在 App Info 中看到授予此权限。系统的行为应该是这样的,它只要求用户一次授予一次,而不是随后(当然,除非权限被撤销)。这在 Nexus 6P 和 5X 上都按预期工作 运行 6.0.1.

if(askForPermissions && act != null) {
 String[] permissionsToRequest = _getPermissions(set);
 ActivityCompat.requestPermissions(act, permissionsToRequest, GENERIC_SVC_PERM_REQUEST);
}else{
 startSmartServices();
}

你的 Moto X Play 运行 是 6.0 还是 6.0.1?这似乎是他们在 6.0.1 中修补的系统错误之一,因为这两个设备 运行 M 的最新更新似乎都有效。我证实它也适用于我的 nexus 6p 和 5x。

如果您不使用 ContextCompat.checkSelfPermission() 检查您是否已经拥有权限,那么这将导致重复请求相同的权限。根据此处的文档:http://developer.android.com/training/permissions/requesting.html

"The user only needs to grant permission once for each permission group. If your app requests any other permissions in that group (that are listed in your app manifest), the system automatically grants them. When you request the permission, the system calls your onRequestPermissionsResult() callback method and passes PERMISSION_GRANTED, the same way it would if the user had explicitly granted your request through the system dialog box."

可能是系统自动授予访问权限,如上文在 6.0.1 中所述,但会在 6.0 中明确向用户显示相同的对话框(依赖开发人员在请求之前使用 checkSelfPermission)。