1
我嘗試了以下方法,但總是返回PackageManager.PERMISSION_DENIED,雖然我知道我有權讀取該文件。有任何想法嗎?如何檢查已使用意向發送的URI的權限?
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();
}
啊,現在我明白了。我總是必須知道我想要檢查的權限。但那不是我想要的。我想知道我是否可以讀取文件。有時候還有其他應用程序允許發送文件,但是我的應用程序沒有讀取它們的權限。所以我必須趕上SecurityException ... – mohlendo 2011-06-11 09:49:25