简体   繁体   中英

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..

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.

Hmm i just started an emulator, got a root shell with adb shell and started unmounting things. It seemed to work just fine.
Had to do umount /mnt/sdcard/.android_secure and then umount /mnt/sdcard on a 2.3.3 VM but it seemed to work. Check what's on your VM with mount before umounting.
Of course this is a much "harsher" solution than umounting from the Android UI - kind of simulates an user that removes the sd card without umounting it first - but it may help with your testing.

You can't mount/unmound virtual SD card while the emulator is running as explained here (re)mounting the SD card on android emulator

If you want to test your app, I suggest you to find a real device.

Sorry for my ignorance but why can't you go to Android Setting menu then select Storage and unmount SD card? You can mount it back in same way. It works under emulator called using Eclipse. My version ADT adt-bundle-windows-x86_64-20140702

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM