Android M:即使用户选择了“不再询问",如何打开“权限对话框"? [英] Android M : How to open Permission Dialog even if user selects Never Ask Again ?

查看:426
本文介绍了Android M:即使用户选择了“不再询问",如何打开“权限对话框"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不是,提示用户设置页面或任何其他解决方案的解决方法是什么?

If not what is the workaround to prompt user to setting page or any other solution ?

推荐答案

如果用户选择不再询问",则无法打开请求权限对话框. 但是您可以向用户显示信息.

You can't open the request permission dialog if user selects Never Ask Again. But you can show the information to user.

@Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_CODE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();
                    // do your work here
                } else if (Build.VERSION.SDK_INT >= 23 && !shouldShowRequestPermissionRationale(permissions[0])) {
                    Toast.makeText(MainActivity.this, "Go to Settings and Grant the permission to use this feature.", Toast.LENGTH_SHORT).show();
                   // User selected the Never Ask Again Option
                } else {
                    Toast.makeText(MainActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    } 

设置屏幕: 要打开设置屏幕,可以使用以下意图.

Settings Screen: To open the settings screen you can use the below intent.

    Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);

有关更多信息,您可以在

For more info you can check the thread on How to programmatically open the Permission Screen for a specific app on Android Marshmallow?

这篇关于Android M:即使用户选择了“不再询问",如何打开“权限对话框"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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