Thursday 8 March 2012

Android Tutorial: Creating and Using an SD Card in the Emulator

The first issue I ran into was trying to load files into the Android emulator. For instance, if you want to load MP3 files on a “real” Android phone, you’ll probably insert an SD card into the phone. The emulator can emulate this, but you need to jump through a few hoops:

1.
    First, you would have created an sd card image file during the creation of avd (android virtual device).

2.
    If you want to access the image, the emulator must be running with the image loaded. I’m going to assume you’re using the Eclipse tools. In there you need to specify the image on the command line. Open the “Run configurations…” dialogue and configure the image as follows (don’t forget to put in the correct directory)


3.
     Next start the emulator and verify that the SD card is loaded. The best way to do this is in the DDMS tool. To access it: click on the open perspective button:

If the DDMS isn’t in the list, click “Other…” and choose it from there. Open the file explorer and you should be able to open the sdcard:



4.
  now you can select any file that you want to move for eg, i want to move an mp3 file to the sd card. so select the mp3 file that you want to move just drag and drop the file on the "sdcard" directory in the file explorer. the file will be pushed into the sd card in the emulator.

 if you cannot follow the above point then do as follows
Add files to the sdcard: There are two options: either you can use the two icons in the top right corner of the DDMS tools () or you can use the command line tools. The following command pushes the file to your sdcard:
adb push myfile.mp3 /sdcard/


5.
And that’s it. the file should appear in the DDMS file explorer. Next time, we’ll try to actually do something with the file we places on the Android emulator.

important point is that when you push or add any files to the sd card in the emulator, its better to restart the emulator. this ensures that files have been moved and the emulator will configure the sd card and scan it for your files.



No comments:

Post a Comment