【发布时间】:2015-12-02 21:00:00
【问题描述】:
我正在测试对应用程序的拒绝权限,我看到当询问权限状态时,它返回的是已授予而不是拒绝。
我正在根据 Google 指南检查权限状态:
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
Manifest.permission.CAMERA)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.CAMERA},
PERMISSIONS_REQUEST_TAKE_PHOTO);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
这是它在第一个 if 中实际返回的内容:
状态“0”表示 PackageManager.PERMISSION_GRANTED
这会产生java.lang.RuntimeException: Fail to connect to camera service 错误。
DEVICE IS A NEXUS 5X
最好的问候。
【问题讨论】:
-
你的 targetSdkVersion 是什么?
-
@laalto 最初它的 21 也尝试了 23,结果相同。
-
对于低于 23 的任何
targetSdkVersion,您应该获得PERMISSION_GRANTED,即使用户在“设置”中关闭了该权限组。建议您完全卸载应用,将targetSdkVersion设置为23,然后再试一次。 -
@CommonsWare 感谢您回答马克。我会试试的。另请注意,此事件正在生成 CameraView 类以调用 Camera.open() 返回 EACCESS (-13) 错误。我将对此进行测试并更新。
-
是androidManifest中声明的权限吗?
标签: android android-camera android-6.0-marshmallow