checkSelfPermission()似乎不适用于WRITE_EXTERNAL_STORAGE [英] checkSelfPermission() doesn't seem to work for WRITE_EXTERNAL_STORAGE

查看:413
本文介绍了checkSelfPermission()似乎不适用于WRITE_EXTERNAL_STORAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用的应用 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

它是在Android 6.0上自动授予的,但是我可以在设置中将其撤消. 想检查它是否被授予以防用户撤销它,所以我这样做:

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?

推荐答案

您缺少的内容:targetSdkVersion为23或更高.

You are missing something: a targetSdkVersion of 23 or higher.

如果targetSdkVersion为22或更低,则无法从设置中确定用户是授予还是撤消了权限.

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.

这篇关于checkSelfPermission()似乎不适用于WRITE_EXTERNAL_STORAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆