5

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

I 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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Akshata
  • 271
  • 2
  • 7
  • 11

5 Answers5

11

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sephy
  • 50,022
  • 30
  • 123
  • 131
  • 1
    +1 for providing the method for an existing AVD (my case, because I was clueless when I followed the instructions on how to setup an Android development environment for the first time). However, neither this answer nor the AndroidBlogger post mention what the path to the card is. Empirically, I discovered that it is created in the tools directory, e.g. C:\android-sdk-windows\tools\FirstSDCard – Android Eve Nov 16 '10 at 19:10
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Adrian Fâciu
  • 12,414
  • 3
  • 53
  • 68
0

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jonas Söderström
  • 4,856
  • 2
  • 36
  • 45
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rich
  • 36,270
  • 31
  • 115
  • 154
-1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    A case of self plagiarism: This answer is the exact same as [user3612615's answer to *Move to SD card on Android*](https://stackoverflow.com/questions/7135441/move-to-sd-card-on-android/23521747#23521747) ([first revision](https://stackoverflow.com/revisions/23521747/1)). – Peter Mortensen Sep 23 '21 at 17:39