checkSelfPermission() doesn't seem to work for WRITE_EXTERNAL_STORAGE

时间:2015-11-04 15:34:32

标签: android runtime-permissions

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 个答案:

答案 0 :(得分:4)

你遗失了一些东西:targetSdkVersion为23或更高。

如果您的targetSdkVersion为22或更低,则您无法确定用户是否从“设置”中授予或撤消了该权限。