1. Problem description: purchase ZTE v955 as a mobile phone, but in order to save costs (the virtual SD card space of the mobile phone system is 1.7 GB, meeting actual requirements), it is not necessary to buy an external memory card. Write a program to save images and a large amount of data on the SD card.
If (environment. getexternalstoragestate (). equals (environment. media_mounted) {// the file can be stored externally. File F = new file (environment. getexternalstoragedirectory (), picfilepath); If (! F. exists () {f. mkdirs ();}
Determine and detect the SD card. The detection result is that v955 does not have an external storage SD card (SD is not installed in reality ). I have found many methods and cannot access the SD card. At last, we found that the storage structure of ZTE v955 is/mnt/sdcard2 through ddms of eclipse. Because there is no external SD card, we use environment. getexternalstoragedirectory () cannot access/mnt/sdcard (actually does not exist ),
String file = "/mnt/sdcard2/" + PICFILEPATH;File f = new File(file);if (!f.exists()) {f.mkdirs();}
To access the virtual SD card of the mobile phone. To ensure that the program can be used on a mobile phone with an SD card, the following judgment can be made:
Public static file getpicbasefile () {If (environment. getexternalstoragestate (). equals (environment. media_mounted) {// the file can be stored externally. File F = new file (environment. getexternalstoragedirectory (), picfilepath); If (! F. exists () {f. mkdirs () ;}return F ;}else if (new file ("/mnt/sdcard2 ")). exists () {// special mobile phone, such as ZTE v955. The memory card is sdcard2string file = "/mnt/sdcard2/" + picfilepath; file F = new file (File ); if (! F. exists () {f. mkdirs () ;}return F ;}else {return NULL ;}}
Finally Meet the software requirements.
Conclusion: If the mobile phone comes with external storage or virtual storage, you can check the SD card path through the above method. Different mobile phone/mnt/sdcard2 methods are different, some may be/mnt/sdcard0. You can view the access path of the SD card through ddms of Eclipse.