I want to let the user safely remove the SD card in my program, but it seems the Android 2.2 public API does not provide a way to do this. Does anyone know what's a proper way to do it?
2 Answers
You need to take the user to the device's built-in Settings. I think this will work.
Intent i = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS);
startActivity(i);
Unmounting the SD card is one of those actions which could be used maliciously if it wasn't under full user control. If it could be done purely in software (without user intervention) then code could disrupt other apps running on the device.

- 48,735
- 19
- 103
- 135
-
1"code could disrupt other apps running on the device": especially now that applications can be located on the SD card. Not to mention all the users photos/music would be located on the SD card – Kurru Jan 08 '11 at 03:35
-
@Kurru: Exactly! This is why there is a warning that 'some applications may stop and may be unavailable until you remount the SD card' when I do it with my phone. There are so many ways it could cause problems. As you say, having photos/music on the SD card will also reduce what the built-in Gallery and Music apps have access to. – Squonk Jan 08 '11 at 03:59
Indeed on the Logitech Revue (the Google TV companion box) that Intent call launches the Storage control panel which gives user access to the Unmount command for safe removal. If you just pull the USB device out on that unit it is experienced as an Unsafe/unexpected removal and your card could be left in proverbial disarray if treated that way. Thanks for the hint, very useful.
The Revue by the way have an unusual arrangement with the /sdcard unit built in, so if you plug in an external SD card via USB adapter or use some USB stick it will show up under /mnt/ as a name beginning with "usb" and some number. So you have three storage areas on that unit, internal, the built in "sdcard" and USB ports where drives will mount when inserted.
I haven't earned enough points yet to be allowed to include a snapshot of how the panel looks.

- 1,381
- 10
- 14