The following line of code
context.getApplicationContext().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
raises this exception when running on devices with API level 19 (KitKat), but not on later versions:
java.lang.IllegalArgumentException: Requested flags 0x40, but only 0x3 are allowed
at android.os.Parcel.readException(Parcel.java:1476)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.grantUriPermission(ActivityManagerNative.java:3461)
at android.app.ContextImpl.grantUriPermission(ContextImpl.java:1732)
at android.content.ContextWrapper.grantUriPermission(ContextWrapper.java:577)
Why is that so?
I believe this is caused by a change added in KitKat which should have fixed content access but they broke it.
You would need to run a check using Build.VERSION.SDK_INT < 19 (ie. pre-KitKat)
if(Build.VERSION.SDK_INT < 19) {
context.getApplicationContext().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
} else {
takePersistableUriPermission(packageName, uri);
}
http://developer.android.com/reference/android/content/ContentResolver.html#takePersistableUriPermission
I think this is a bug in KitKat.
https://android.googlesource.com/platform/frameworks/base/+/kitkat-mr2.2-release/services/java/com/android/server/am/ActivityManagerService.java#6214
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION is missing in check condition.
from lolipop version, it works correctly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With