Unable to access the SD card

Source: Internet
Author: User

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.

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.