在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
不会在外部存储的根目录上抛出异常?