Android obtains the Mount path of all memory cards.

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.