checkSelfPermission() doesn't seem to work for WRITE_EXTERNAL_STORAGE

隐身守侯 提交于 2020-01-02 08:34:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!