我一直在扫描/etc/vold.fstab以获得外部存储列表。在Android 4.3删除Google文件之前,它都可以正常工作。我知道现在使用了统一的/fstab.*文件,但是如果没有root用户,则无法访问该文件。
因此,在Android 4.3中,我应该怎么做才能获取外部存储列表?
我的代码看起来像这样。现在,它包括不可移动的内部存储和可移动的外部存储。
File voldFile = new File("/system/etc/vold.fstab");
fr = new FileReader(voldFile);
br = new BufferedReader(fr);
String line = br.readLine();
while (line != null) {
if (line.startsWith("dev_mount")) {
String[] tokens = line.split("\\s");
File mountPoint = new File(tokens[2]);
if (mountPoint.isDirectory() && mountPoint.canRead())
list.add(tokens[2]);
}
line = br.readLine();
}
我最终扫描了/ proc / mounts输出以获取当前已安装的存储。类似于下面的代码。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
File voldFile = new File("/proc/mounts");
fr = new FileReader(voldFile);
br = new BufferedReader(fr);
String line = br.readLine();
while (line != null) {
Log.d(TAG, line);
if (line.startsWith("/")) {
String[] tokens = line.split("\\s+");
if ("vfat".equals(tokens[2])) {
File mountPoint = new File(tokens[1]);
if (!tokens[1].equals(defaultMount))
if (mountPoint.isDirectory() && mountPoint.canRead())
list.add(tokens[1]);
}
}
line = br.readLine();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句