Android get all memory card mount paths

Source: Internet
Author: User

Recently due to project requirements, need to find files on the memory card, the test found that some of the mobile phone mount Path can not find, here to share an effective method.

/** * Get all memory card mount paths * @return */public static list<string> Getmountpathlist () {list<string> Pathli          st = new Arraylist<string> ();          Final String cmd = "cat/proc/mounts";              Runtime run = Runtime.getruntime ();//Get current JVM Runtime environment try {Process p = run.exec (cmd);//execute command              Bufferedinputstream InputStream = new Bufferedinputstream (P.getinputstream ());                BufferedReader BufferedReader = new BufferedReader (new InputStreamReader (InputStream));              String Line;                   while (line = Bufferedreader.readline ()) = null) {//Get command after execution in console output information logger.i (line);                Output information content:/data/media/storage/emulated/0 Sdcardfs rw,nosuid,nodev,relatime,uid=1023,gid=1023 0 0                  string[] temp = textutils.split (line, "");                  The analysis shows that the second space is followed by a path String result = Temp[1];                 File File = new file (result); Type is directory, readable, writable, even if it is a mount path if (file.isdirectory () && file.canread () && file.canwrite ()) {                      LOGGER.D ("Add--" +file.getabsolutepath ());                  Pathlist.add (result);                      }//Check whether the command failed to execute if (p.waitfor ()! = 0 && p.exitvalue () = = 1) {                  P.exitvalue () ==0 indicates normal end, 1: Abnormal End logger.e ("command execution failed!");              }} bufferedreader.close ();          Inputstream.close ();          } catch (Exception e) {LOGGER.E (e.tostring ());          command to execute the exception, add the default path Pathlist.add (Environment.getexternalstoragedirectory (). GetAbsolutePath ());      } return pathList;  }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android get all memory card mount paths

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.