How to safely remove an SD card programmatically on Android

I want the user to safely delete the SD card in my program, but it seems that the open Android 2.2 API does not allow this. Does anyone know how to do this correctly?

+7
source share
2 answers

You need to take the user to the device’s built-in settings. I think it will work.

Intent i = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS); startActivity(i); 

Disconnecting the SD card is one of those actions that can be used maliciously if they are not under the full control of the user. If this can be done exclusively in software (without user intervention), then the code may interfere with the operation of other applications running on the device.

+9
source

In fact, in Logitech Revue (a companion application for Google TV), an Intent call launches the Storage control panel, which gives the user access to the Unmount command for safe deletion. If you simply pull out the USB device on this device, it is perceived as unsafe / unexpected deletion, and your card may be left in the notorious mess if it is processed in this way. Thanks for the tip, very helpful.

Revue, by the way, has an unusual layout with the built-in / sdcard module, so if you connect an external SD card via a USB adapter or use a USB drive, it will appear under / mnt / as a name starting with "usb" and some numbers. Thus, you have three storage areas on this device, internal, built-in "sdcard" and USB ports where the drives will be mounted when inserted.

I have not earned enough points to allow the inclusion of a snapshot of how the panel looks.

0
source

All Articles