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

37 Comments

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

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

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

    what should i do

  4. Hi. It was an useful article. Thanks

  5. Elbombardi

    Thanks budy!

  6. Jay

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

  7. channa

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

    ./emulator -sdcard my128MbCard .

    Regards,
    Channa

  8. Vaibhavdi

    Hay, Thanks buddy steps are working as it is…

  9. demonrodd

    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

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

  11. UltraBlue

    thanks. that was helpful

  12. poonkodinatarajan

    hi

    this is very useful and working well.thank you

  13. Guille

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

  14. Rakesh

    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

  15. Wajid

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

  16. can you explain for windows

  17. vermasque

    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

  18. andria

    Hi

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

    Thanks

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

  20. P-a

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

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

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

  23. Sarita

    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 ?

  24. Ramachandran.M

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

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

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

  27. I’m now not certain where you are getting
    your info,however glod topic. I must spend some time learning more or
    understanding more. Thanks for wonderful information I used to be onn the lookout for
    this info ffor my mission.

Trackbacks for this post

  1. Faster start up of the Android Emulator « catairborne android development
  2. Le Repaire du Sanglier des Ardennes » Blog Archive » [Android] Environnement de développement
  3. Working with Android SD Cards image on Mac « 2cupsOfTech
  4. Creating folder on the sdcard in the android avd emulator | ChrisDoesDev.com
  5. Working with SD cards in the Android emulator « Savin
  6. My Homepage

Leave a Reply