Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SD card issues

I currenlty have a few problems with developing an APP and using the external SD card.

  • The first problem is that I check if there is a SD card mounted. This function returns a true even if there is no SD card inserted. I've used/tried the following code:

    • https://stackoverflow.com/a/12721994
    • http://tsicilian.wordpress.com/2012/04/24/android-persistence-external-storage-sd-card/

from developer.android.com

Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

Maybe that is a problem?

I'm using a LG L5 (E610)

I've added the correct permission to the manifest file.

My other issue could be related to this issue

Any help is very much appreciated. Thank you.

like image 764
Rik Avatar asked Oct 19 '12 09:10

Rik


People also ask

Can an SD card cause phone problems?

But a small but persistent number of Android owners are blaming SD card-related problems for causing their smartphones to spontaneously crash and lose precious data.


1 Answers

You said:

The first problem is that I check if there is a SD card mounted. This function returns a true even if there is no SD card inserted.

I think you stumbled upon something that takes some time to grasp, because it's not cristal clear at all.

In Android you will find 2 kinds of memory:

  • The system one, always available, highly secured: your app can only access a small part of it dedicated for you and other apps cannot read your data there.
  • The shared one, often called public, external, or "sdcard". Every app have read/write access to all of it. But it is not always available, as you can "mount" it on your computer, having the effect to unmount it in android and therefore hiding it. (but only before android 3.X).

You will find 3 kinds of devices in the wild:

  • On some devices, this shared memory is on a chip soldered inside the device. so the name sdcard is not adequate. But still, the path might be "/sdcard"
  • On other devices, this shared memory is on a real sdcard that you can remove.
  • On some other devices this memory is for a part on a chip, and for another part on your sdcard.

Based on what you said I think you are on the 3rd kind of device. So your physical sdcard will be found in this kind of path: /mnt/sdcard/external_sd/. Sadly, this is device specific, I don't think there is something in the Android API to get this path.

Also, bear in mind than, since Android 3.X, we don't need to "mount" this shared memory anymore. So your shared memory will always be there for Android as we are now using MTP protocol.

This is why isExternalStorageAvailable() returns true, even if your sdcard is removed.

like image 90
pcans Avatar answered Oct 02 '22 19:10

pcans