Search code examples
androidsd-cardmountunmount

android mount unmount sd card


I am working on an application that scans the sd card. At this time, I am using the emulator of eclipse to test my android application. I have created a virtual sd-card for testing purposes on eclipse.

I want to know if there is any way of un-mounting and then mounting the sd card on the emulator (eclipse) so that I can test my application that when the sd-card is unmounted, it should generate a message etc..

Can anyone help me here..


Solution

  • It is possible to boot the device without the external storage, which allows you to test what happens when you do not get the Environment.MEDIA_MOUNTED state.

    Just create an AVD with an existing SD card .iso file. Then, rename the file. When you load this AVD, it will work just fine but it won't have the external storage loaded. This allows you to test your logic for when the external media isn't mounted.

    I created a separate AVD for testing the no-external-storage scenario, but you could rename the .iso file and restart the emulator if you want to run both tests on the same one.

    I did try the umount method above, and while it's useful (as Torp mentions, it's a harsher test), the system still thinks the SD card is mounted and my alternate logic isn't run.