Tuesday, September 20, 2011

Emulating an SD card on the Android Emulator

Many a times, we need the SD card to store data. But how can one do this in the emulator? Well, here's how.
It's a simple 2 step process:
1. Create an image of the SD card
On the command prompt, navigate to the "\Android SDK\tools" directory.
eg. D:\AndroidDev\Android SDK\tools>
Give the command
mksdcard 128M MySDCard
That's it. Your SD card image is ready.

2. Using the SD card in eclipse
In the Package explorer, right click on your project and select "Run As>Run Configurations..."

In the right panel, select Target tab.
In the text box provided for Additional Emulator Command Line Options, enter the following:
-sdcard <full path to your sd card image file>

Once this is done, click on Run and the SD card is accessible!
On subsequent runs, we do not need to set up the command line option again. It's just to be done ONCE.