Grant permission required for EXTERNAL_STORAGE in

2019-01-11 20:28发布

Will the Android permissions WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE trigger the new grant permission dialog of Android M?

6条回答
叼着烟拽天下
2楼-- · 2019-01-11 20:56

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-11 20:56

According to Android docs you don't need to request permission about read and write external storage.

Edit: in the latest Android M release you need to ask for both read and write permissions

查看更多
家丑人穷心不美
4楼-- · 2019-01-11 20:59

I solved add this if check version for Android M

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                    requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
            }
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-11 21:00

My answer is based on my tests on M Preview SDK version 2, using an emulator.

If you target MNC preview API level, WRITE_EXTERNAL_STORAGE is not granted by default and will be part of the new dynamic permission API.

You will see the storage permission as a toggle button in the new app permissions menu in device settings, and you can use Activity.requestPermissions to show the popup for that permission.

However if you target api level < MNC, it won't be classified as a dangerous permission, and thus will be granted without a way for the user to disable it (not showing up in permission settings), and you will not be able to compile code using Activity.requestPermissions anyway as the preview SDK enforces minSdkVersion="MNC" to use the new APIs.

This is a different behavior than location permissions: whatever the API level you target, the user will be able to turn location off in permission menu.

For the permission menu itself, the permission toggle state is ON by default if:

  • Target API level < MNC.
  • Target API level = MNC but you upgrade app on device from a previous install where target API level was less than MNC.

Otherwise you will see the toggle as OFF by default.

Hope it helps.

查看更多
相关推荐>>
6楼-- · 2019-01-11 21:06

Storage permission falls under dangerous protection level, So all the dangerous protection level permissions will not be granted at install time in Android M, if App target SDK is set to 23. They will be given at run time. And yes these permissions can be revoked at run time also.

No permission dialog will not be triggered automatically, you need to do a request by using API such as requestPermissions() method to show that native dialog.

Please check the dangerous level permission list here

查看更多
甜甜的少女心
7楼-- · 2019-01-11 21:10

According to the docs:

Limited Permissions Granted at Install Time: When the user installs or updates the app, the system grants the app all permissions that the app requests that fall under PROTECTION_NORMAL.

So because READ_EXTERNAL_STORAGE is falling under PROTECTION_NORMAL , it won't trigger the dialog.

But because the level of WRITE_EXTERNAL_STORAGE is PROTECTION_DANGEROUS, it will fall under this behavior as described in docs:

User Grants Permissions at Run-Time: When the app requests a permission, the system shows a dialog to the user, then calls the app's callback function to notify it whether the permission was granted. If a user grants a permission, the app is given all permissions in that permission's functional area that were declared in the app manifest

Here is the sources for the protection level:

detailed list

查看更多
登录 后发表回答