Android various models, various system versions, how to get the external sdcard path

Source: Internet
Author: User

Because of the project needs, in the case of external sdcard, may not want to directly put in-app data into the built-in sdcard, I specifically wrote a function to get the SDcard path

If you have an external sdcard to get an external sdcard, if you do not use the system default "external SDcard" (in-depth study may know that this external sdcard is actually from the built-in SDcard a partition from the inside of it)

Directly below the code:

public static string Getsdcardpath () {string cmd = "cat/proc/mounts";        Runtime run = Runtime.getruntime ();        Bufferedinputstream In=null;        BufferedReader Inbr=null;            try {Process p = run.exec (cmd);            in = new Bufferedinputstream (P.getinputstream ());            INBR = new BufferedReader (new InputStreamReader (in));            String Linestr;                while ((Linestr = Inbr.readline ()) = null) {LOG.I ("Commonuitls", linestr); if (Linestr.tolowercase (). Contains ("SDcard". toLowerCase ()) && linestr.contains (". Android_se                    Cure ")) {string[] Strarray = Linestr.split (" "); if (Strarray! = null && strarray.length >= 5) {String result = Strarray[1].replace ("/.a                        Ndroid_secure "," ");                        LOG.I ("Commonuitls", result);                    return result;     }           } if (Linestr.tolowercase (). Contains ("EXTSD". toLowerCase ())) {string[] Strarray =                Linestr.split ("");                LOG.I ("Commonuitls", strarray[1]);                return strarray[1]; } if (p.waitfor () = 0 && p.exitvalue () = = 1) {LOG.E ("Commonuitls", "CMD cat/proc/ Mounts error! ");}}        catch (Exception e) {e.printstacktrace ();        LOG.E ("Commonuitls", e.tostring ());            }finally{try {if (in!=null) {in.close ();            }} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();            LOG.E ("Commonuitls", e.tostring ());         } try {if (inbr!=null) {inbr.close (); }} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();    LOG.E ("Commonuitls", e.tostring ());} } return Environment.getexTernalstoragedirectory (). GetPath ();} 


Android various models, various system versions, how to get the external sdcard path

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.