始终不授予OS 4.0上的Android Marshmallow权限模型READ_EXTERNAL_STORAGE权限 [英] Android Marshmallow permission model on OS 4.0 READ_EXTERNAL_STORAGE permission always not granted

查看:101
本文介绍了始终不授予OS 4.0上的Android Marshmallow权限模型READ_EXTERNAL_STORAGE权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android OS 4.0上运行我的应用程序并请求具有以下内容的READ_EXTERNAL_STORAGE权限时,我遇到问题:

I have a problem when running my app on Android OS 4.0 and requesting READ_EXTERNAL_STORAGE permission with:

ActivityCompat.requestPermissions(ctx, requestedPermissions, requestCode);

我总是在回调上

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) { 

grantResults != PackageManager.PERMISSION_GRANTED

使用ActivityCompat.checkSelfPermission检查权限总是返回permissionDenied.

Checking the permission with ActivityCompat.checkSelfPermission is always returning permissionDenied.

通过在系统对话框中请求权限,它在OS 6.0上运行良好. 除了4.0之外,Android OS 4.x始终会授予该权限. OS 4.0中其他权限(相机,日历,联系人,电话)的行为都很好,除了READ_EXTERNAL_STORAGE导致此问题.

It works well on OS 6.0 by requesting the permission with system dialog. Android OS 4.x excepted the 4.0 the permission is always granted. OS 4.0 the other permissions (Camera,Calendar,Contact,Phone) are behaving well except the READ_EXTERNAL_STORAGE causing this issue.

也许是操作系统问题?

推荐答案

如果您使用的是Android 6.0以上版本,则

  • 调用真实的requestPermissions(),或者

    • call through to the real requestPermissions() if you are on Android 6.0+, or

    使用PackageManager查看您是否在旧版Android上拥有请求的权限

    use PackageManager to see if you hold the requested permissions on older versions of Android

    READ_EXTERNAL_STORAGE的问题在于它是在API级别16(Android 4.1)中添加的.您不能在比该版本更旧的Android上使用它,原因很简单,原因是它不存在.

    The problem with READ_EXTERNAL_STORAGE is that it was added in API Level 16 (Android 4.1). You cannot hold it on older versions of Android than that, for the simple reason that it did not exist.

    要么:

    • 将您的minSdkVersion设置为16,或

    请输入您自己的逻辑来处理这种情况,因为认识到READ_EXTERNAL_STORAGE在API级别16之前是不相关的

    Put your own logic in to handle this case, recognizing that READ_EXTERNAL_STORAGE is irrelevant prior to API Level 16

    这篇关于始终不授予OS 4.0上的Android Marshmallow权限模型READ_EXTERNAL_STORAGE权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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