如何在android中使用AccessController?

时间:2015-05-29 05:44:08

标签: android file-permissions android-external-storage

在Android应用程序(API级别10)中,我未在manifest中使用以下权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

因此,应用程序不会在外部存储的根目录上写入。但是当我尝试通过此代码通过read/write检查AccessController权限时:

File f = Environment.getExternalStorageDirectory();
String path = f.getAbsolutePath();
String actions = "read,write";
try {
    AccessController.checkPermission(new FilePermission(path, actions));
    Log.d("Tag", "You have read/write permition to use : " + path);
} catch (AccessControlException e) {
    Log.d("Tag", "You have not read/write permition to use : " + path);
} catch (SecurityException e) {
    Log.d("Tag", "You have not read/write permition to use : " + path);
}

结果将是:

  

您有使用的读/写权限:/ storage / sdcard0

那么,当应用程序无权在其上写入时,为什么AccessController.checkPermission不会在外部存储的根目录上抛出异常?

0 个答案:

没有答案