API 26+: WRITE_EXTERNAL_STORAGE permission is always denied

前端 未结 2 638
野趣味
野趣味 2020-12-14 02:18

I have switched my app to target API 27 and now it can\'t be granted WRITE_EXTERNAL_STORAGE permission -- grantResult is always -1.

相关标签:
2条回答
  • 2020-12-14 02:45

    I noticed a space in my permission in manifest, it was <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE "/> and I changed it to <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> and problem solved.

    0 讨论(0)
  • 2020-12-14 02:55

    Somewhere along the line, you are picking up that android:maxSdkVersion="18" attribute. My guess is that it is coming from a library. Check the "Merged Manifest" tab in Android Studio, when you are editing your own manifest. It will have details of what is contributing the various elements and attributes.

    android:maxSdkVersion has the effect of removing your <uses-permission> element on higher Android SDK versions, at least in terms of how runtime permissions work.

    Since you need this permission for all versions, adding tools:remove="android:maxSdkVersion" on the <uses-permission> element should revert the android:maxSdkVersion="18" and give you what you expect.

    0 讨论(0)
提交回复
热议问题