开发者

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 == Pac开发者_开发问答kageManager.PERMISSION_DENIED) {
    Toast.makeText(getApplicationContext(),
    "No permissions to read the file", Toast.LENGTH_LONG).show();
    finish();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜