Android Content Resolver takePersistableUriPermission API below 19 no such method

2.2k views Asked by At

I`m using this in order to achieve the following behavior:

User selects files via Intent.ACTION_OPEN_DOCUMENT for API above 19 (The new Storage Access Framework) or via Intent.ACTION_GET_CONTENT for API below 19. The files should be stored in the app`s list for later use (open them). So after I get the files I use:

Uri uri = fileUri;
final int takeFlags = data.getFlags()
          & (Intent.FLAG_GRANT_READ_URI_PERMISSION
          | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getApplicationContext().getContentResolver().takePersistableUriPermission(uri, takeFlags);

For the cases of API above 19 it works fine, but for API below 19, for example I test with API 14, I got ANR with following error:

java.lang.NoSuchMethodError: android.content.ContentResolver.takePersistableUriPermission

What can be the problem? Thanks,

UPDATE: It seems it`s (Persistent Permission) done automatically in API below 14, which means just comment out this code if API is below 14.

0

There are 0 answers