checkSelfPermission() 似乎不适用于 WRITE_EXTERNAL_STORAGE
checkSelfPermission() doesn't seem to work for WRITE_EXTERNAL_STORAGE
我有使用的应用程序
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
它在 Android 6.0 上自动授予,但我可以在设置中撤销它。
想检查它是否被授予以防用户撤销它,所以我这样做:
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
//OK permission granted, let's do stuff
} else {
//I'll better ask for permission
}
有趣的是,条件总是满足,甚至权限被手动撤销。然后应用程序失败了...对我来说它看起来像是一个错误,是它还是我遗漏了什么?
您缺少一些东西:targetSdkVersion
23 或更高。
如果您的 targetSdkVersion
为 22 或更低,您无法确定用户是从“设置”中授予还是撤消了权限。
我有使用的应用程序
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
它在 Android 6.0 上自动授予,但我可以在设置中撤销它。 想检查它是否被授予以防用户撤销它,所以我这样做:
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
//OK permission granted, let's do stuff
} else {
//I'll better ask for permission
}
有趣的是,条件总是满足,甚至权限被手动撤销。然后应用程序失败了...对我来说它看起来像是一个错误,是它还是我遗漏了什么?
您缺少一些东西:targetSdkVersion
23 或更高。
如果您的 targetSdkVersion
为 22 或更低,您无法确定用户是从“设置”中授予还是撤消了权限。