7

I am developing an application that needs to write files to the SD card. I am using GetExternalStoragePublicDirectory() to determine the directory to write to.

I have two phones I am developing with. On a Google Nexus S, running Android 4.0.4 (Ice cream sandwich) it is returning a directory on the SD card. However, on a Samsung Exhibit 2 running Android 2.3.5, it is writing directly to the USB storage on the phone.

Is there a way to force the SD card?

edit:

I found that getExternalStoragePublicDirectory(), and getExternalStorageDirectory() are always returning "/mnt/sdcard/". This is not actually the mount location for the sd card. On the Samsung Exhibit 2, this is the USB storage location. The card mount location is "/mnt/sdcard/external_sd". Is there a way to return this actual sd location?

I see that the camera and other apps have found a way to do it. The camera app has a "storage" setting with options "phone" and "memory card". If "memory card" is specified, images are actually stored on the sd card.

Kevin Westwood
  • 7,739
  • 8
  • 38
  • 52
  • 1
    +1 "Android will run always the same on all devices", better we use "platform independent development" hahaha. Motorola Defy: sdcard-ext ( not underscore) –  Sep 19 '12 at 13:30

2 Answers2

2

Is there a way to return this actual sd location?

No, sorry, not in the current Android SDK.

I see that the camera and other apps have found a way to do it.

Mostly, they will either be ones written by the device manufacturer, or are reading information via MediaStore, which should index both sources.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

If you want to write to SD card only use

File mySdCardPath = Environment.getExternalStorageDirectory();
File dir = new File (mySdCardPath.getAbsolutePath() + "/yourDirectoryName");
Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78
  • 1
    The described solution has the same behavior on both phones as using GetExternalPublicDirectory("yourDirectoryName"). The directory that is returned from GetExternalStorageDirectory() is actually "/mnt/sdcard". Apparently on the Samsung Exhibit 2, this is the USB Storage. The actual sdcard is at "/mnt/sdcard/external_sd". Apparently this is a known problem. see: http://stackoverflow.com/q/5694933/758074 – Kevin Westwood Apr 13 '12 at 23:46