How to use AccessController in android?

别说谁变了你拦得住时间么 提交于 2019-12-10 11:36:53

问题


In an Android application (API level 10),I do not use below permission in manifest:

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

So application would not write on root of external storage.But when I try to check read/write permission via AccessController by this code:

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);
}

Result will be:

You have read/write permition to use : /storage/sdcard0

So why AccessController.checkPermission does not throw exception on root of External Storage when application has no permission to write on it?

来源:https://stackoverflow.com/questions/30521951/how-to-use-accesscontroller-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!