android mount unmount sd card

旧城冷巷雨未停 提交于 2019-12-08 07:51:53

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/6968264/android-mount-unmount-sd-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!