Get external storage list in Android 4.3

I scanned /etc/vold.fstab to get a list of external repositories. It works fine until Android 4.3 deletes the Google file. I know that the unified file /fstab.* is now used, but which is not accessible without root.

So, in Android 4.3, what should I do to get a list of external storage?

My code looks something like this. Now it includes both non-removable internal and removable external storage.

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(); } 
+4
source share
1 answer

I have finished the output of / proc / mounts for the current mounted storage. Code similar to below.

  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(); } } 
+1
source

Source: https://habr.com/ru/post/1500036/


All Articles