Working with external storage in the Android emulator could be a little tricky and the documentation is not easy to find. I’ll try to give a brief walk through of the steps needed to create a SD card image, mount the image in Linux, put content on it and use it in the emulator.
Creating a SD card image
In both the 1.1 and 1.5 version of the SDK there is a tool called mksdcard located in the
SDK Install Dir/tools folder. Simply run
./mksdcard 128M my128MbCard
to create a 128Mb SD card with the name my128MbCard.
Mounting a SD card image in Linux
To be able to put content on to the card you can mount the card in Linux. It will then simply appear as a folder in the filesystem.
First make a directory in the /media folder:
sudo mkdir /media/mycard
Then mount the card as a loopback device:
sudo mount -o loop my128MbCard /media/mycard
Adding content to the card
With content we usually mean media content like images and videos. Images and videos are located in a folder called
/dcim/Camera. You could of course add any content to the card. When you are done copying your files be sure to umount the card otherwise it will not be usable from the emulator.
sudo umount /media/mycard/
Using the card in the emulator
Google added something called Android Virtual Device (AVD) to the SDK 1.5. To create a new AVD using our newly created SDcard image run the following:
./android create avd --name myAVD --target 2 --sdcard my128MbCard
Target 2 means that we want to use the 1.5 API features in the device. Now we simply fire up the emulator and start using our content:
./emulator -avd myAVD
More information about the new SDK can be found here: SDK