ActivityCompat.requestPermissions() 请求的可接受权限是什么?

What are acceptable permissions for ActivityCompat.requestPermissions() to request?

在我使用 Java 的 Android 应用程序中,我定义了一个 checkForPermission() 方法来检查单个权限的授予状态。如果尚未授予权限,它会使用 ActivityCompat.requestPermissions().

向用户请求此权限

方法如下:

private boolean checkForPermission(String permission, int rationaleMessageId, int requestCode) {

    // Check if permission is already granted.
    if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

        // Permission has not been granted. Check if a rationale AlertDialog should be shown.
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

            // Show rationale AlertDialog explaining why this permission is needed.
            new AlertDialog.Builder(this)
                    .setTitle(R.string.rationale_dialog_title)
                    .setMessage(rationaleMessageId)
                    .setPositiveButton(android.R.string.ok,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    // Request permission again.
                                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
                                }
                            })
                    .create()
                    .show();
        }

        // Do not show rationale AlertDialog. Just request permission again.
        else {
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
        }
        return false;
    }

    return true;
}

我注意到该方法对于 android.permission.WRITE_EXTERNAL_STORAGE 等简单权限非常有效,但不适用于 android.permission.WRITE_SETTINGS.

等更危险的权限

我想知道 ActivityCompat.requestPermissions() 实际可能请求哪些类型的权限。我的假设是必须使用其他方式请求危险权限,但我希望得到任何关于此的反馈。谢谢。

具体来说,requestPermissions() 用于 protectionLeveldangerous 的权限。

WRITE_EXTERNAL_STORAGE is dangerous. WRITE_SETTINGS is not.