from:http://blog.csdn.net/u011290399/article/details/10363881
In the project, the discovery of an external sdcard via an Android-provided API has not been successful and has not had much time to solve the problem
At the end of last week, we finally had a moment to study the problem.
Search on the Internet, the results of Baidu search engine how to do not give me the search results to meet the needs
However, the search out of the built-in sdcard and the external SDcard interchange operation gives the idea
First look at the path of SDcard:/storage/extsdcard,/storage/sdcard0,/storage/sdcard0/external-sdcard,/storage/external-sdcard, and so on
Many of the more down-to-the-wall methods on the Web:
1. Get the file object of the parent path through the Android API, then get an array of path strings within the files object, traverse and look for the SDcard path, and see the SDcard path given above can not be fully implemented
2, through the StorageManager class reflection to obtain the getvolumepaths result set, tests a mobile phone to pass, but does not have much safeguard
3, write Dead path ... This could be a programmer's word, and he saw the guy who cursed the word.
4, according to the online search out of the external, built-in SDcard interchange operation, think whether can read Vold.fstab files, direct access to external sdcard path, the results found that many mobile phones can not find vold.fstab files ...
Although the Vold.fstab file could not be found, the information in the file was stored in the memory of the phone, so the method came.
// private static String cmd = "mount"; Private Static String cmd = "cat/proc/mounts"; Private Static String format = "SDcard"; Private Static String sdcard = Environment.getexternalstoragedirectory (). GetAbsolutePath ();
/*** Access to the absolute path of the external sdcard *@return */ Public StaticString Getexternalpath () {BufferedReader read=NULL; String External_sdcard=SDcard; Runtime Runtime=Runtime.getruntime (); Try{Process Process=runtime.exec (CMD); Read=NewBufferedReader (NewInputStreamReader (Process.getinputstream ())); String Line; while(line = Read.readline ())! =NULL) {//if (Line.tolowercase (). Contains (format) && line.contains (". Android-secure")) { if(Line.tolowercase (). Contains (format)) {string[] array= Line.split (""); if(Array! =NULL&& Array.Length >= 5) {String temp= Array[1].replace ("/.android_secure", "" "); if(!sdcard.equals (temp)) {External_sdcard=temp; } } } } } Catch(Exception e) {External_sdcard=SDcard; E.printstacktrace (); } finally{ioutils.freeresource (read,NULL); } returnExternal_sdcard; }
Android Internal, external SDcard