How to grant permission Manifest.permission.MANAGE

2019-01-28 13:26发布

问题:

I want to grant the permission Manifest.permission.MANAGE_DOCUMENTS, but when I run the app, the dialog of the permission should appear but it doesn't. Here's my code:

int hasCameraPermission = ContextCompat.checkSelfPermission(MemoryDetail.this, Manifest.permission.MANAGE_DOCUMENTS);
if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) {
    if (!ActivityCompat.shouldShowRequestPermissionRationale(MemoryDetail.this, Manifest.permission.MANAGE_DOCUMENTS)) {
        showDialogMessage("Need use permission: MANAGE_DOCUMENTS", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    requestPermissions(new String[] {Manifest.permission.MANAGE_DOCUMENTS}, Database.PICK_PICTURE);
                }
            }
        });

    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{Manifest.permission.MANAGE_DOCUMENTS}, Database.PICK_PICTURE);
    }
    return;
}

回答1:

MANAGE_DOCUMENTS is a signature-level permission. Ordinary Android apps cannot hold it. Only apps that were signed by the same signing key that signed the firmware can hold it.