开发者

How to install SD card on Android emulator (1.6)

I want to install an SD card on Android emulator (1.6). I am using Eclipse 3.4.0.

I 开发者_Go百科found one command to install an SD card:

mksdcard

But where should I execute it?

I tried in Dev toolsTerminal Emulator.

But it is giving an error:

permission denied


The easiest way to make sure your SD card is properly associated to your emulator instance is to create an AVD with an SD card. Do it as follows:

In Eclipse: Menu WindowAndroid SDK and AVD managerNew:

  • give a name to your AVD (no space allowed)
  • give a SDK target
  • give size to the wanted SD card
  • create the new AVD

Or, the second solution: you already have your own AVD and you want to add an SD card to it:

  • open a command prompt or terminal (Windows / Linux?)

  • cd to your sdk/tools directory

  • execute the following: mksdcard 256M NameOfYourCard

    (you can pass the size you want of course)

And then put the following in your run configuration in the "Launch Additional command line" field:

-sdcard fullPathToYourCard

It should work. If it's not clear, have a look in here for more detailed procedure.


You can use the Android tool mksdcard, a command-line utility available in the SDK/tools/ directory.

Here's a complete tutorial on how to do this.


I create all my virtual devices through the dialog in Eclipse. Menu WindowAndroid SDK and AVD ManagerNew (button). It has input controls for SD card specifications.


From the command line you can do the following. Go to the /tools folder of the SDK.

Create an Android profile with the SD card:

android.bat create avd -n jonas2 -t 1 -c 256M

Start the emulator

emulator.exe -avd jonas2


If you are using Eclipse, just click on the Android Device Manager icon, then click on the Android Device Manager tab, if you've already create an AVD just select it, then click on the "Edit Button" on the right side, then locate where SD Card is then change size to you prefer number "e.g: 256 or 512 or 1024" and make sure that you have enough "Internal storage capacity", then click on the "OK" button. Now go to the "Run Configuration" and start your AVD emulator, in the setting of AVD you should see that your SD Card is "Mounted".

This should work.

If you want to add a file or folder into your SD Card just do the following:

Steps:

  1. Open your Android application's source code file with a text or programming editor.

  2. Browse to the location in the source code where you wish to call the function that writes a file to the device's external storage.

  3. Insert this single line of code to check for the SD card:

    File sdCard = Environment.getExternalStorageDirectory();

  4. Insert these lines of code to set the directory and file name:

    File dir = new File (sdcard.getAbsolutePath() + "/folder1/folder2"); dir.mkdirs(); File file = new File(dir, "example_file");

  5. Replace "/folder1/folder2" in the above code with the actual path where you intend to save the file. This should be a location in which you normally save your application files. Also, change the "example_file" value to the actual file name you wish to use.

  6. Insert the following line of code to output the file to the SD card:

    FileOutputStream f = new FileOutputStream(file);

Finally step 7:

Save the file, then compile it and test the application using the Android emulator software or the device.

This will works!!! ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜