1
我正在测试拒绝应用程序的权限,并且我看到当它询问允许返回的状态而不是被拒绝时。Android M - 摄像头权限被拒绝返回PERMISSION_GRANTED
我检查,根据谷歌的指南权限的状态:
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.
}
}
下面是它居然在第一,如果返回:
国家“ 0“表示PackageManager.PERMISSION_GRANTED
这产生了一个java.lang.RuntimeException: Fail to connect to camera service
错误。
DEVICE IS A NEXUS 5X
此致敬意。
什么是你的targetSdkVersion? – laalto
@laalto最初21与23也尝试,同样的结果。 – FeleMed
即使用户在设置中切换了该权限组,您也应该为23以下的任何'targetSdkVersion'获得'PERMISSION_GRANTED'。我建议你完全卸载应用程序,将你的'targetSdkVersion'设置为23,然后再试一次。 – CommonsWare