如何在 Android 模拟器上安装 SD 卡 (1.6)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2788451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:23:39  来源:igfitidea点击:

How to install SD card on Android emulator (1.6)

android

提问by Akshata

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

我想在 android 模拟器 (1.6) 上安装 SD 卡。我正在使用 Eclipse 3.4.0

I found one command to install SD card:

我找到了一个安装 SD 卡的命令:

mksdcard

But where to execute it I am not getting??

但是在哪里执行它我没有得到?

I tried in Dev tools-> Terminal Emulator

我在开发工具->终端模拟器中尝试过

But it is giving error : permission denied

但它给出了错误:权限被拒绝

Thank you..

谢谢..

回答by Sephy

this 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: Window=> android SDK and AVD manager=>New :

确保您的 SD 卡正确关联到您的模拟器实例的最简单方法是使用 SD 卡创建 AVD。这样做:在 Eclipse 中: Window=> android SDK and AVD manager=>New :

-give a name to your AVD (no space allowed)
-give a SDK target
-give size to the wanted SDcard
-create the new AVD

- 为您的 AVD 命名(不允许使用空格) -
提供 SDK 目标
- 为所需的 SD 卡提供大小 - 创建
新的 AVD

Or, 2nd solution, you already have your own AVD and you want to add a 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 ofc)

或者,第二种解决方案,您已经拥有自己的 AVD 并且想要向其中添加 SD 卡:打开命令提示符或终端(windows/linux?)cd 到您的 sdk/tools 目录执行以下命令:
mksdcard 256M NameOfYourCard
(您可以通过你想要的尺寸 ofc)

and then, put the following in you run configuration in the "Launch Additional command line" field :

然后,将以下内容放入“启动附加命令行”字段中的运行配置中:

-sdcard fullPathToYourCard

-sdcard fullPathToYourCard

It should work. If it's not clear, have a look in herefor more detailled procedure

它应该工作。如果不清楚,请查看此处了解更详细的程序

回答by Adrian Faciu

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

您可以使用 android 工具,这是 SDK/tools/ 目录中提供的命令行实用程序。

Here'sa complete tutorial on how to do this.

这是有关如何执行此操作的完整教程。

回答by Jonas S?derstr?m

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

从命令行您可以执行以下操作 转到 sdk 的 /tools 文件夹

Create Android profile with SD card

使用 SD 卡创建 Android 配置文件

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

Start Emulator

启动模拟器

emulator.exe -avd jonas2

回答by user3612615

If you are using Eclipe, 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".

如果您使用的是 Eclipe,只需点击 Android 设备管理器图标,然后点击 Android 设备管理器选项卡,如果您已经创建了一个 AVD 只需选择它,然后点击右侧的“编辑按钮”,然后找到 SD 卡的位置,然后将大小更改为您喜欢的数字“例如:256 或 512 或 1024”并确保您有足够的“内部存储容量”,然后单击“确定”按钮。现在转到“运行配置”并启动您的 AVD 模拟器,在 AVD 的设置中,您应该看到您的 SD 卡已“安装”。

This should work.

这应该有效。

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

如果要将文件或文件夹添加到 SD 卡中,只需执行以下操作:

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:

1) 使用文本编辑器或编程编辑器打开 Android 应用程序的源代码文件。2) 浏览到源代码中您希望调用将文件写入设备外部存储的函数的位置。3) 插入这行代码来检查 SD 卡:

File sdCard = Environment.getExternalStorageDirectory();

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

4) 插入这几行代码来设置目录和文件名:

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.

5) 将上面代码中的“/folder1/folder2”替换为您打算保存文件的实际路径。这应该是您通常保存应用程序文件的位置。此外,将“example_file”值更改为您希望使用的实际文件名。

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

6) 插入下面这行代码,将文件输出到SD卡:

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.

保存文件,然后编译它并使用 Android 模拟器软件或设备测试应用程序。

This will works!!! ;-)

这会奏效!!!;-)

回答by Rich

I create all my virtual devices through the dialog in Eclipse. Window > Android SDK and AVD Manager > New (button). It has input controls for SD card specs.

我通过 Eclipse 中的对话框创建了我所有的虚拟设备。窗口 > Android SDK 和 AVD 管理器 > 新建(按钮)。它具有 SD 卡规格的输入控件。