Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check the permission of an URI that has been send with an intent?

I have tried the following but this always returns PackageManager.PERMISSION_DENIED although I know that I have the right to read the file. Any ideas?

Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);

// check uri permissions but does not work
int perm = checkUriPermission(uri , "r", null,
        Binder.getCallingPid(), Binder.getCallingUid(),
        Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (perm == PackageManager.PERMISSION_DENIED) {
    Toast.makeText(getApplicationContext(),
    "No permissions to read the file", Toast.LENGTH_LONG).show();
    finish();
}
like image 680
mohlendo Avatar asked Jan 17 '26 09:01

mohlendo


1 Answers

r is not a permission. Try passing null for the second parameter, or use the version of checkUriPermission() that skips the two String parameters you have in the second and third positions.

like image 108
CommonsWare Avatar answered Jan 19 '26 23:01

CommonsWare