我在清单文件中指定了WRITE_EXTERNAL_STORAGE权限,在应用程序中调用requestPermissions时,grantResult返回-1,表示未授予。然而,在设备设置中,该应用的存储权限显示为已开启。但是该应用程序不允许我进行写入操作。为什么授权请求失败,并且该应用程序认为权限被拒绝,但在设置中显示为正常?
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, PICK_FROM_GALLERY);
.
.
.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
} else {
//THIS IS WHERE I END UP WITH grantResults == -1
}
requestPermissions()
中列出的所有内容都需要出现在清单中。还要注意,您只需要WRITE_EXTERNAL_STORAGE
,而不是这两个权限。 - CommonsWare