Android M:即使用户选择Never Ask Again,如何打开权限对话框?

Sak*_*ana 3 android android-6.0-marshmallow

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

Dee*_*yal 6

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

@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;
        }
    } 
Run Code Online (Sandbox Code Playgroud)

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

    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);
Run Code Online (Sandbox Code Playgroud)

有关详细信息,您可以查看如何以编程方式打开Android Marshmallow上特定应用程序的权限屏幕的主题?