在MIUI中检查权限READ_CONTACTS [英] Check permissions READ_CONTACTS in MIUI

查看:327
本文介绍了在MIUI中检查权限READ_CONTACTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试检查权限 在我设置的清单中

I try to check permissions in my Manifest I set

<uses-permission android:name="android.permission.READ_CONTACTS" />

然后在片段中尝试检查

int permissionCheck = ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.READ_CONTACTS);

但是,尽管OS中的应用程序属性具有任何允许状态,但我只能得到0. 我在Android 4.4.4 MIUI 6.5.1中签入 可能是MIUI中的原因

But I get only 0 despite of any state of permission in application properties in OS. I checked in Android 4.4.4 MIUI 6.5.1 May be the reason in MIUI

如果我尝试检查清单中没有的许可权,则得到-1,但是我想知道许可权的切换状态.

I have got -1 if I try check permission which there isn't in Manifest, but I wanna know the switch state of the permission.

感谢

推荐答案

将此函数添加到您的代码中,并仅在MIUI中调用READ_COntacts的checkUsagePermission()

Add this function to your code and call checkUsagePermission() for READ_COntacts only in MIUI

private boolean checkUsagePermission() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        AppOpsManager appOps = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
        int mode = 0;
        mode = appOps.checkOpNoThrow("android:read_contacts", android.os.Process.myUid(), getPackageName());
        boolean granted = mode == AppOpsManager.MODE_ALLOWED;
        if (!granted) {
           //write your code here for accept that permission 
            return false;
        }
    }
    return true;
}

这篇关于在MIUI中检查权限READ_CONTACTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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