SD Card with Eclipse/Emulator
Creating the SD Card "image" file (a file representation of a physical SD Card) Assume Cygwin bash shell: $ cd c: $ mkdir sdcards $ cd sdcards $ Android\android-sdk\tools\mksdcard -l mysdcard 32M sdcard1 ( size <8M will give warning that card cannot be used with emulator, but it will still create the card. You will receive a warning if you try to start an emulator with it: $ emulator -avd MyEmulator-sdcard sdcard1 ### WARNING: SD Card files must be at least 9MB, ignoring 'sdcard1' ) $ ls sdcard1.img
Android Debug Bridge (adb) Overview ADB - Android Debug Bridge - http://developer.android.com/guide/developing/tools/adb.html -Server -Clients (shell utils, DDMS, ADT plugin) -A daemon, running as a background process on each emulator or device instance. client - shell, [script] Emulator (5554): 5555 (virtual sdcard) client - DDMS ADB - Server: 5037 Ports 5555-5585 Eclipse - ADT plugin Device (5556): 5557 (physical sdcard not available w/usb?) The ADB manages communication between clients and devices. This is why you can kill eclipse and the emulator keeps running. They are independent processes communicating through adb. It also explains why DDMS can get a little flaky. You might have to get the clients/server to start talking with each other again and there can be a lag.
Ways to add sd card to emulator 1) Command line emulator launch: $ emulator -avd MyEmulator -sdcard C:\sdcards\sdcard1 OR $ emulator @MyEmulator -sdcard C:\sdcards\sdcard1 (If path to card is wrong: "...ignoring non-existing SD Card image" on emulator startup)
Ways to add sd card to emulator 2) Eclipse AVD Manager: Edit... SD Card: File: C:\sdcards\sdcard.img
Ways to add sd card to emulator 3) Eclipse: RunConfigurations... Select your app Target Tab "Additional Emulator Command Line Options": < -sdcard C:\sdcards\card1.img > Next step is to push some data to the card...
Pushing Data to the sdcard on a running emulator with the Dalvik Device Manager Server * This can be a little flaky if DDMS is already running when you start the emulator. Remember the client server relationship between the clients (DDMS, shell), adb and the emulator daemon. If all else fails, restart Eclipse with emulator still running to get this to work 1) Open DDMS perspective in Eclipse 2) Open mnt folder 3) Open sdcard folder (Note the permissions to the right of the folder: d---rwxr-x) 4) Select the "Push a file onto the device" icon 5) Browse and select a file to push to the card Interesting: Open DDMS before you start the emulator. Watch the initialization of the emulator in DDMS. You will see the mount points, etc come online over time. It's a good visual way to understand that it may be sometime before everything is available to your app.
DDMS - Dalvik Device Manager Server
Pushing Data to the sdcard (with adb) -Probably the easiest way $ adb push c:/pics/device.png /sdcard/listview.png ^--This is the actual mounted file sys on the device. This shows as /mnt/sdcard in DDMS, but it's accessible here as /sdcard. // After issuing this command you will see listview.png in the DDMS listing of files under /mnt/sdcard, // but...i had to restart the emulator for the image to be available in the device's gallery. To "pull" a file from the device's card: $ adb pull /sdcard/listview.png Note: This did not remove the file from the card, it just pulled a copy. To remove I had to go through DDMS or the device itself.
Things to Consider Something maintains a lock on the pictures directory. Not sure what. I had to bounce Eclipse/Emulator to get the sd card to be recognized. Remember client-server nature of adb Try the "reset adb" button in DDMS (not sure it works, but it's in the dropdown menu next to the screen capture button. The real SD Card on your physical device will not be available when you have your device connected to your PC with USB cable. A real pain for testing. Workaround anyone? Open AVD Manager, start the emulator- note the start up emulator components in DDMS, observer how sdcard takes some time to mount Make sure sdcard in DDMS has write permissions When pushing files to sdcard in DDMS: "Failed to push the item(s). null" - There is a pathing/naming issue to the sdcard's location