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