权限对话框未显示android marshmallow

时间:2015-10-06 11:31:45

标签: android android-6.0-marshmallow

我使用nexus 6 android 6.0,仅针对WRITE_EXTERNAL_STORAGE权限对话框未显示其正在显示的其他危险权限。

final private int REQUEST_CODE_ASK_PERMISSIONS = 123;

@TargetApi(Build.VERSION_CODES.M)
private void insertDummyContactWrapper() {
    int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    // Here, thisActivity is the current activity
    if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    110);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }
}

构建

defaultConfig {
        applicationId "com.example.application"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

清单:

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"

1 个答案:

答案 0 :(得分:2)

  

仅针对WRITE_EXTERNAL_STORAGE权限对话框未显示其正在显示的其他危险权限

您的其他dangerous权限为READ_EXTERNAL_STORAGE。当我们要求权限并检查权限时,在Android 6.0用户界面中,用户授予(或拒绝)权限READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGE属于同一群组。

因此,如果用户之前已经批准了READ_EXTERNAL_STORAGE的请求,那么当您致电WRITE_EXTERNAL_STORAGE时,您已经拥有checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);