I have switched my app to target API 27 and now it can\'t be granted WRITE_EXTERNAL_STORAGE
permission -- grantResult
is always -1
.
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.
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.