Simon
Simon

Reputation: 2066

How to use FLAG_GRANT_PREFIX_URI_PERMISSION with the Android Storage Access Framework?

I want to use the Storage Access Framework (SAF) in Android to get and save in a local database the uri of a large amount of files (>600).

So to get 1 file's uri, I call:

intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
startActivityForResult(intent, RESULT_FILE_OPEN)

then in the onActivityResult, I persist the permission granted:

getContentResolver().takePersistableUriPermission(intent.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION);

But I know Android 11 limits to 512 the permissions that you can persist. So I thought I could use the flag Intent.FLAG_GRANT_PREFIX_URI_PERMISSION to grant access to files whose uri has a prefix match thus reducing the number of persisted uri permissions.

But I have no clue on how to use this flag. The way I used it, I can't get read access to the files with a prefix match.

So my question is:

How the flag Intent.FLAG_GRANT_PREFIX_URI_PERMISSION is supposed to be used?

Upvotes: 2

Views: 587

Answers (0)

Related Questions