Tuesday, April 23, 2013

Create an Android Emulator SD Card and Write Data To It

Create the SD Card...

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:
Let's create a 64MB sd card for our Android emulator, shall we?
Linux
From a terminal...
# cd ~/android-sdk-linux/tools
# ./mksdcard 64M ~/Desktop/sdcard.iso
Windows XP
From a DOS prompt...
Actually where is your android-sdk-windows exists.
cd C:\Program Files\android-sdk-windows\tools
mksdcard 64M c:\documents and settings\tyler\desktop\sdcard.iso
Now you can use the 'Eclipse Android SDK and AVD Manager' to create a new android virtual device that can use the path to the sd card you created.

Write Data to the SD Card...

Linux
From a terminal...
# cd ~/android-sdk-linux/tools
# ./ddms
Windows XP
From a DOS prompt...
cd C:\Program Files\android-sdk-windows\tools
ddms
This will start the Dalvik Debug Monitor Server. Next...
  1. Launch your AVD with SD card from Eclipse that you created earlier
  2. From DDMS, go to 'Device -> File Explorer' 
  3. Select the 'sdcard' folder
  4. Click the 'push file onto device' button
  5. Find your file and click open
That's it!
Now from inside your code you can get to the sd card's path with: Environment.getExternalStorageDirectory()

No comments:

Post a Comment