【问题标题】:Permissions - How do I request and/or change them in phones running MIUI during runtime?权限 - 如何在运行时运行 MIUI 的手机中请求和/或更改它们?
【发布时间】:2017-01-23 07:57:51
【问题描述】:

显然 MIUI OS 在 Marshmallow 之前已经实现了自己的权限系统。我目前正在测试小米 4i 的视频录制应用程序,它使用基于 API 21 [Android 5.0.2] 的 MIUI,它需要 MIUI 权限管理器默认未授予的录制音频权限。

到目前为止,我设法更改权限的方法是通过单击 AlertDialog 中的“确定”按钮访问应用程序的“权限管理器”窗口:

isMIUI = MIUIUtils.isMIUI();
if(isMIUI)
{
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setMessage("If you intend to use the video recording feature, please enable the 'Record Audio' permission in the settings menu. You will be redirected there if you press OK.")
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
                intent.putExtra("extra_pkgname", "com.picmix.mobile");
                startActivity(intent);
            }
        })
        .setNegativeButton("CANCEL", null)
        .create();
    adb.show();
}

但这对我来说还不够好。我需要检查 Record Audio 权限是否已在 MIUI 权限管理器中检查,以便仅运行一次。

如何以编程方式在 MIUI 权限管理器中检查授予或通知的权限?

【问题讨论】:

    标签: android permissions


    【解决方案1】:
    private boolean resourceCanBeAccessed() {
    
            boolean response = true;
    
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if(ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
                        == PackageManager.PERMISSION_DENIED ) {
    
                    ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.RECORD_AUDIO}, 1);
                    response = false;
                }
            }
            return response;
        }
    

    你只需要在访问资源之前调用这个方法。如果授予权限,此方法将返回 true。如果未授予权限,则将授予权限

    【讨论】:

    • 这仅适用于 Android 6.0 (Marshmallow)。小米米 4i 被识别为 Android 5.0.2 (Lollipop),此代码将只为 Manifest 中定义的所有内容返回 true [顺便说一下,Record Audio 权限在那里]。 MIUI 权限管理器让事情变得比这更复杂。
    猜你喜欢
    • 2017-09-14
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    相关资源
    最近更新 更多