Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Emulator QVGA中的SD卡存在问题_Android_Android Emulator - Fatal编程技术网

Android Emulator QVGA中的SD卡存在问题

Android Emulator QVGA中的SD卡存在问题,android,android-emulator,Android,Android Emulator,我的应用程序使用SD卡上的数据目录来存储文件。在启动时,如果该目录不存在,它将创建该目录。出于某种原因,这在我设置的不同AVD上都能工作,只是如果我将分辨率设置为QVGA,它就无法工作 代码很无聊: File root = new File("/sdcard/mydir"); if(!root.exists()) { try { root.mkdir(); } catch... mkdir()返回false 知道为什么吗?可能是您在创建QVGA AVD时忘记了设置SD卡。请

我的应用程序使用SD卡上的数据目录来存储文件。在启动时,如果该目录不存在,它将创建该目录。出于某种原因,这在我设置的不同AVD上都能工作,只是如果我将分辨率设置为QVGA,它就无法工作

代码很无聊:

File root = new File("/sdcard/mydir");
if(!root.exists()) {
  try {
    root.mkdir();
  }
  catch...
mkdir()返回false


知道为什么吗?

可能是您在创建QVGA AVD时忘记了设置SD卡。请尝试重新设置

此外,您不应该硬编码到外部存储的路径。解释访问外部存储的一些API

下面的代码段可能检测到一些装载问题。 boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // Something else is wrong. It may be one of many other states, but all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false; } 布尔值mExternalStorageAvailable=false; 布尔值mExternalStorageWriteable=false; String state=Environment.getExternalStorageState()

if(环境、介质、安装等于(状态)){ //我们可以读写媒体 mExternalStorageAvailable=mExternalStorageWriteable=true; }else if(Environment.MEDIA\u MOUNTED\u READ\u ONLY.equals(state)){ //我们只能阅读媒体 mExternalStorageAvailable=true; mExternalStorageWriteable=false; }否则{ //还有一些问题。它可能是许多其他州中的一个,但我们所需要的就是它 //要知道,我们既不会读也不会写 mExternalStorageAvailable=mExternalStorageWriteable=false; }
原来我忘了将SD卡权限添加到我的清单中:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


未经许可,该程序可在除QVGA以外的所有模拟器上运行,甚至在我的Droid上运行。

我已多次设置AVD。它肯定应该有SD卡。我设置它的方式与其他屏幕尺寸的一样,但由于某些原因,QVGA无法工作。不过,谢谢你的其他建议。这是给我的!在emulator设置中,我将SD卡字段留空,可以肯定的是,我的emulator有一个/mnt/sdcard,但它无法使用。谢谢