Sai
Sai

Reputation: 15738

Permission dialog is not being shown android marshmallow

Im using nexus 6 android 6.0, only for WRITE_EXTERNAL_STORAGE permission dialog is not showing for other dangerous permission it is showing.

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.
        }
    }
}

Build:

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

Manifest:

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

Upvotes: 2

Views: 2836

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007624

only for WRITE_EXTERNAL_STORAGE permission dialog is not showing for other dangerous permission it is showing

Your other dangerous permission is READ_EXTERNAL_STORAGE. While we ask for permissions and check for permissions, in the Android 6.0 UI, the user grants (or denies) permission groups. READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are in the same group.

So, if the user previously granted your request for READ_EXTERNAL_STORAGE, you will already have WRITE_EXTERNAL_STORAGE at the point in time when you call checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);.

Upvotes: 3

Related Questions