Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write file to sd card and not usb storage

Tags:

android

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.

like image 306
Kevin Westwood Avatar asked Apr 13 '12 23:04

Kevin Westwood


People also ask

How do I use my SD card as storage instead of internal storage?

To do this, insert the SD card and select “Setup.” Choose “Use as internal storage.” NOTE: Android will erase the contents of the drive, so be sure you've backed up any data on it. You can then choose to move photos, files, and some apps to the new device, if you like. If not, you can choose to migrate this data later.

Why I cant use SD card as internal storage?

For newer Android version, there are certain that has no option to format SD Card as internal storage, Android 10 is one of the example. Another tip, make sure to always start with a blank SD Card as it will be formatted and encoded.


Video Answer


1 Answers

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.

like image 155
CommonsWare Avatar answered Nov 14 '22 23:11

CommonsWare