Working with SD cards in the Android emulator

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

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:

Then mount the card as a loopback device:

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.

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:

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:

More information about the new SDK can be found here: SDK

36 Responses to “Working with SD cards in the Android emulator”

  1. At this time I am ready to do my breakfast, later than having my breakfast coming over again to read further news.

  2. Android APP says:

    I was recommended this web site by my cousin. I’m now not certain whether or not this publish is written by way of him as no one else realize such designated about my difficulty. You’re wonderful! Thanks!

  3. Ramachandran.M says:

    I didn’t get what I want. so poor service.

  4. My Homepage says:

    … [Trackback]…

    [...] Read More: jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/ [...]…

  5. Sarita says:

    Thanks Buddy ! It is working. By the way what is the idea behind mount and unmount ? If anyways we are going to unmount then why mount ?

  6. Krishna says:

    Hi
    If you are using Eclipse it is very easy to create SD card at the time of creating a new virtual device.

  7. Thanks !!!
    I will try it and i wil tell you about the results.

  8. P-a says:

    In OSX, just name the image .iso and type ‘open mycard.iso’ and it will be mounted and available in Finder

  9. ramiz says:

    while creating itself select sd card .its simple.then using file explorer from window->view you can store and retrive data on sdcard!!!!

  10. andria says:

    Hi

    Do you know how to make a sdcard with partition in the sdcard?

    Thanks

  11. vermasque says:

    Helpful explanation. I made a Bash script for testing my Android app that does the things above: https://github.com/vermasque/song-alarm/blob/master/tests/make_sdcard.sh

  12. Lisvid com says:

    can you explain for windows

  13. Wajid says:

    I am using Android SDK by Eclipse on windows 7 environment. How can i create folder in somelocation of SD card?

  14. [...] can use the DDMS perspective on Eclipse (www.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/) to view the sd card on the running emulator, and can copy files to the root folder, but I [...]

  15. Rakesh says:

    Thanks a lot for sharing.

    But i want to make one small application which will check status of my External storage,Add files or pictures into External storge ,and read that data from Gallery folder of my emulator.

    Can u help me to accomplish my app.

    Thanks

  16. Guille says:

    very useful paper.. Thank you..
    A question…
    The sdcard format is FAT. Is possible to change this format to ext2 or ext3 format ?
    Thanks in advance!!

  17. poonkodinatarajan says:

    hi

    this is very useful and working well.thank you

  18. UltraBlue says:

    thanks. that was helpful

  19. [...] an sd card and connect that sd card image with the an android emulator. The post by Jayway team (http://www.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/) helped me to get started but those instructions are linux specific and didn’t work for me on [...]

  20. Matthew says:

    Great way to transfer files in an emulator!! I’m using Android 2.1, waiting for the Google I/O conference news! This is wonderful!

  21. demonrodd says:

    Thanks a lot man….it helped me to access the sdcard in linux……i am using the 2.1 version of the SDK……though the last two steps for emulator are not needed if you are using eclipse for developing apps…..in eclipse go to
    Run->Debug Configurations->Target->Addtional Emulator command line options, type the following

    -sdcard /the path where we have created the my128MbCard/my128MbCard

    once again thanks a lot

  22. Vaibhavdi says:

    Hay, Thanks buddy steps are working as it is…

  23. channa says:

    Hey,
    For the last steps of creating AVD, Can we use the -sdcard option for the emulator?

    ./emulator -sdcard my128MbCard .

    Regards,
    Channa

  24. Jay says:

    I figured this out on Windows, in case anyone needs that info. Go to http://www.androidref.com and look for How to create an SD card, store a contact photo, and display the photo on the handset..

  25. Elbombardi says:

    Thanks budy!

  26. sheff says:

    Hi. It was an useful article. Thanks

  27. Andy says:

    When I try to mount, it says
    mount: -o loop: option not supported

    what should i do

  28. Elad says:

    What do you do if you don’t have linux?

  29. [...] 14, 2009 First of all, you may wish to have a look here, and setup a memory card in your project directory called my128MbCard if you want to use any of the [...]

  30. Kathryn says:

    Thanks for this tutorial!! :) It was very helpful.

Leave a Reply