Android obtains the Mount path of all memory cards.
Recently, due to project requirements, you need to find files on the memory card. After testing, we found that some mobile phone Mount paths could not be found. Here is an effective method.
/*** Get all storage card Mount paths * @ return */public static List
GetMountPathList () {List
PathList = new ArrayList
(); Final String cmd = cat/proc/mounts; Runtime run = Runtime. getRuntime (); // get the current JVM runtime environment try {Process p = run.exe c (cmd); // execute the command BufferedInputStream inputStream = new BufferedInputStream (p. getInputStream (); BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (inputStream); String line; while (line = bufferedReader. readLine ())! = Null) {// obtain the output information Logger in the console after the command is executed. I (line); // output information:/data/media/storage/emulated/0 sdcardfs rw, nosuid, nodev, relatime, uid = 1023, gid = 1023 0 0 String [] temp = TextUtils. split (line,); // The analysis content shows that the second space is followed by the path String result = temp [1]; File file = new File (result ); // The type is directory, readable, and writable, even if it is a mount path if (file. isDirectory () & file. canRead () & file. canWrite () {Logger. d (add --> + file. getAbsolutePath (); pathList. ad D (result);} // check whether the command execution fails if (p. waitFor ()! = 0 & p. exitValue () = 1) {// p. exitValue () = 0 indicates that the Logger ends normally, and 1 indicates that the Logger ends abnormally. e (command execution failed !);} BufferedReader. close (); inputStream. close ();} catch (Exception e) {Logger. e (e. toString (); // If a command execution exception occurs, add the default path pathList. add (Environment. getExternalStorageDirectory (). getAbsolutePath ();} return pathList ;}