问题
I have the app that uses
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
It's automatically granted on Android 6.0, but I can revoke it in the settings. Wanted to check if it's granted in case user revokes it, so I do this:
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
}
Funny thing is that the condition is ALWAYS fulfilled, even the permission was revoked manually. And the the app fails... It looks like a bug to me, is it or am I missing something?
回答1:
You are missing something: a targetSdkVersion
of 23 or higher.
If your targetSdkVersion
is 22 or lower, you have no ability to determine whether a permission was granted or revoked by the user from Settings.
来源:https://stackoverflow.com/questions/33525800/checkselfpermission-doesnt-seem-to-work-for-write-external-storage