Android. No SD card available - android

My friend is testing my application which uses the SD card to store some settings. He has a Samsung Galaxy S2 but he just told me that he hasn't got an SD card in his device. It seems that the device created a folder in the phone's memory which simulates the existence of an SD card and that is where all app files that used the Sdcard are stored.
Is this a feature available for all Android devices? Should I consider the fact that there is no SD card on a device or should I not bother? Not sure if I should check for SD card availability in my app or not.
P.S. I've just noticed that the same goes for the emulator if I don't specify memory for the SD card.

You definitely should check for sdcard availability. On some devices it might work (as you said), but on some not, and you could get a FileNotFoundException.
So it's worth checking.

String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.toString().equals(
state.toString())) {
//////then do your work here////////
}
another solution: https://stackoverflow.com/a/7429264/6451573

Related

Where is the code for SD card storage option in CyanogenMod's camera app?

I'm using CyanogenMod 10.2.1 on an Xperia ZR. This device has an emulated SD card and a removable SD card. The stock camera app has an option to store images in the emulated or the removable SD card (see screenshots below).
I'm writing a camera app and I want to do the same thing, so I looked at the code of the camera app in Android's source and in CyanogenMod's source. The first uses Environment.getExternalStoragePublicDirectory() and the second Environment.getExternalStorageDirectory(). Neither of those seem to be dynamic, so where does the setting item come from?
Here are some screenshots showing the storage option:
All in all, I want to find out whether those apps use the techniques in Find an external SD card location to access secondary storage.

Android External Storage among mobile brands

I am facing interesting problem. I have discovered, that Samsung in it's own Android phones has two implementations of storage.
1st: /sdcard - is internal memory and /sdcard/external_sd is actually inserted memory card
2nd: /storage/sdcard0 - is internal memory and /storage/ExtSdCard is actually inserted memory card.
My app needs data to be stored in sd card, so I am facing problem, how to determine, which folder might be sd card link or not. Do you know situation of any other Android maker (LG, HTC, Sony), how to cope with external SD cards and how they are visible in android system?
It is really so simple. When you consider your samsung mobiles it is the internal storage that acts as your sdcard.
if you are looking for to save a file in Sdcard, you have to stop hard coding the path like,
/mnt/sdcard.. and so.
instead use, Environment.getExternalStorageDirectory();
This will return the path to your sdcard straight away.
And from there, add Environment.getExternalStorageDirectory()+File.separator+"your directoryname";
And this works for all brands not unique to Samsung.

Android. Not enough room on sdcard

I don't have an Android device to test this (yeah, i know. Android developer without an Android device) but i was wondering if in case there is either NO sdcard in the device, or the sdcard is full, when i need to store some data during the execution of my app, will it return an IOException? Or will it just store it automatically in the phone's memory? OR what happens in this situation, and what are the best steps to pursue?
you could check if the sd card is mounted or not
Is there a way to tell if the sdcard is mounted vs not installed at all?
EDIT:
you can check the availaible space in your phone (sdcard/internal)
How to Check available space on android device ? on SD card?
you might find this useful too.. An IOException IS thrown if you exceed the storage limit.
IOException is thrown when SDCard is full
You can setup the emulator so it uses a SD card and then fill it up with for example "dd". This should give you an environment you can use to test your application in the case when there is no room left on your SD card.

write file to sd card and not usb storage

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.
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.
If you want to write to SD card only use
File mySdCardPath = Environment.getExternalStorageDirectory();
File dir = new File (mySdCardPath.getAbsolutePath() + "/yourDirectoryName");

Fetching Files from SD card and USB to different folders when using getExternalStorage()

Is it possible to sort the files detected from usb and SD Card seperately?.I mean I fornd that using getExternalStorage,we are able to detect all external devices connected to Android device which includes both SD card and USB.
I would like to seperate the files that are detected to 2 seperate folders(Now the files from SD card and USB are detected into same folder)..ie USB files seperately and SD card files seperately.
How to do it?Kindly help
You have to code in the logic to determine if the "external storage" is really external storage. Different devices use a different name - very stupid I agree. In Google's API doc's I'm pretty sure they mention that getExternalStorage() is not guaranteed to grab the external storage as this is manufacturer and device specific.
Knowing this pitfall may assist you in a solution.

Categories

Resources