Grant permission required for EXTERNAL_STORAGE in Android M?

I agree with Guillaume Perrot ‘s answer. I have met the similar question when I write the permission of READ_WRITE_EXTERNAL_STORAGE in AndroidManifest.xml

with no permissions showing up in the app by default , people need to switch the toggle button of storage in the app permissions.Then I modify my targetSdkVersion in build.gradle to less than 23(MNC) and other number related with sdkVersion, the app installed with the permissions on.

The other way is to write requestpermission function in the place that you need the permisson. The code is as follow:

 if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)==
    PackageManager.PERMISSION_GRANTED) {
    //do the things} else {
    requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
      AnyNumber);

Because I have less than 15 reputation so I can’t vote for the Guillaume Perrot ‘s answer.Just use this way to show my idea.

Leave a Comment