Wednesday, February 4, 2009

Tutorial : how to emulate an SD card with the Android emulator

It's important to know how to emulate an SD Card if you're into Android development.
Whether it be because your application actually use it, or to use it for your development, for instance for profiling.

Here are the required step to use an SDCard :

1) Create the emulated SDCard on your real computer :

Google provides a tool just for that, in their SDK/tools directory called mksdcard.
just give it the size of the SdCard you want to create ( in kilobytes or megabytes ) , the name of the resulting file, and you're done :
Open a command prompt, go to your SDK/tool directory, and type :
mksdcard 64M MyNewSdCard

and that's it !

2) Using the emulated SDCard with the emulator

To use the emulated SDCard in the emulator, simply launch the emulator with the '-sdcard EmulatedCard_File_Path' parameter :
So, from the command prompt in the SDK/Tool directory, type :
emulator -sdcard MyNewSdCard

3) Using the emulated SDCard with the emulator from Eclipse :

From eclipse, open the menu entry :
Run / RunConfigurations...

Then on the right panel, choose 'target'
And in the Additionnal Emulator Command Line Options, add
'-sdcard fullPath_to_your_SdCard_File'



And that'all !

4) How to explore the emulated SdCard content and push / pull files from your computer :

Within Eclipse :

Open the DDMS perspective :
Window / Open Perspective / Other... / DDMS

Now select the file explorer tab ( in the right panel ), and you have acces to a classic explorer of your emulated phone, including the sdcard !

Now to push a file from your computer, or pull a file from the emulated device, you have two discrete icons in the upper right corner :


Just use them to to browse and select on your computer the file to pull or push !

Without Eclipse :

Just launch DDMS from the command prompt in the SDK / tools directory.
The file explorer is in the device menu...

14 comments:

Tony said...

Thanks for the tip!

By the way, you have -sdCard with a capital 'C' but I think it's case-sensitive: -sdcard (all lowercase).

AndroidBlogger said...

Hum...
I think you're right, and I'm going to correct my mystake immediatly !!
Thanks for reporting !

Smith said...

Hello friends,

this post is very useful and very interesting to read, Really this blog is nice information,Keep it up.
32GB SD Card

Ty said...

Very well written, thank you

afford said...

I want to create a folder inside the sd card image that I created. I tried dragging the folder into the DDMS but unsuccessful. Does anyone know how to do it?

AndroidBlogger said...

Don't do from DDMS, but from a shell ( using "adb shell" in DOS )

android programmer said...

this post is very useful and very interesting to read.

Anonymous said...

Hi i am getting stuck in the third step i.e. in Run as configuration, after specify the path of sdcard created and i am not able to launch emulator

Anonymous said...

very good indeed , helped me a lot

Sumaya said...

this blog is very helpful

Nadeeshaan said...

Thanks dude.....
This is very much helpful

Anonymous said...

thanks

Keerthi said...

Hi, I am encountering a problem in storing files to SD Card. When I tried to push an image file into /mnt/sdcard, I got the following error -



transfer error: Read-only file system. Failed to push selection: Read-only file system

Can you please help me solve this problem? Thanks in advance.

Santoshi said...

I am too facing the problem mentioned by Keerthi ... did anyone find the solution?