Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
Can';t在Android中创建外部文件目录。存在写入\u外部\u存储器_Android_Android Sdcard - Fatal编程技术网

Can';t在Android中创建外部文件目录。存在写入\u外部\u存储器

Can';t在Android中创建外部文件目录。存在写入\u外部\u存储器,android,android-sdcard,Android,Android Sdcard,我尝试使用我的应用程序上下文和我的呼叫服务的上下文访问外部目录。不幸的是,它不断返回null,并且LogCat报告它无法创建外部目录。我确信我有写入存储\u权限存在,但它仍然无法工作。我的设备运行的是API 10(2.3.3)香草安卓。有什么想法吗 这是我的舱单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"

我尝试使用我的
应用程序上下文
和我的呼叫
服务
上下文
访问外部目录。不幸的是,它不断返回
null
,并且LogCat报告它无法创建外部目录。我确信我有
写入存储\u权限
存在,但它仍然无法工作。我的设备运行的是API 10(2.3.3)香草安卓。有什么想法吗

这是我的舱单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="droid.signboard" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />



<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:name="SignboardApp">
    <receiver android:name=".ApplicationStarter">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            <action android:name="droid.signboard.LAUNCHER_START"></action>
        </intent-filter>
    </receiver>
    <activity android:label="@string/app_name"
        android:screenOrientation="landscape" android:launchMode="singleTop"
        android:name=".view.Signboard">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"></action>
            <category android:name="android.intent.category.LAUNCHER"></category>
        </intent-filter>
    </activity>
    <service android:name=".controller.MasterControllerService">
        <intent-filter>
            <action
                android:name="droid.signboard.LAUNCH_SERVICE_FROM_ACTIVITY"></action>
        </intent-filter>
    </service>


</application>
</manifest>
代码是
可运行
的方法,由
服务
调用。
Runnable
的构造函数将
上下文
作为其参数。这是代码使用的
上下文。代码在日志调用时抛出一个异常,成功,这意味着外部存储存在且可用

尝试修复的更新:

干净的安装不起作用。

还原到API 9不起作用,尽管它在早期就起作用了。

修复了它,但我真的不知道它为什么现在起作用我重新启动设备,然后突然,它又能工作了<代码>上下文#getExternalFilesDir()
停止返回
null
。即使它现在可以工作了(多亏了it人群的Roy和Moss,我应该向Google报告还是什么?

您需要在AndroidManifest.xml中拥有写入外部存储权限。至少,这是我解决问题的原因


在您的
之前添加一行
,这是一个旧线程,但我刚刚遇到了相同的问题,并发现我感到惊讶的原因并不常见。当我的设备连接到computer/Eclipse时,我正在尝试写入外部存储器。。我得到了以下错误

06-25 16:16:09.565:W/ApplicationContext(4290):无法创建外部文件目录 06-25 16:16:09.565:W/System.err(4290):java.io.FileNotFoundException:/full_archive.zip:打开失败:EROFS(只读文件系统) 06-25 16:16:09.565:W/System.err(4290):位于libcore.io.IoBridge.open(IoBridge.java:416) 06-25 16:16:09.565:W/System.err(4290):位于java.io.FileOutputStream。(FileOutputStream.java:88) 06-25 16:16:09.565:W/System.err(4290):位于java.io.FileOutputStream。(FileOutputStream.java:73) 06-25 16:16:09.565:W/System.err(4290):位于com.seine.trophy.database.DownloaderThread.run(DownloaderThread.java:79) 06-25 16:16:09.573:W/System.err(4290):原因:libcore.io.ErrnoException:打开失败:EROFS(只读文件系统) 06-25 16:16:09.573:W/System.err(4290):位于libcore.io.Posix.open(本机方法) 06-25 16:16:09.573:W/System.err(4290):位于libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 06-25 16:16:09.573:W/System.err(4290):位于libcore.io.IoBridge.open(IoBridge.java:400) 06-25 16:16:09.573:W/系统错误(4290):。。。3个以上

这是来自开发者指南

警告:如果用户将外部存储器装载到计算机上,则外部存储器可能不可用


只需将手机从我的电脑/IDE上取下,我就解决了这个问题

发布androidmanifest.xml文件。发布代码和任何相关堆栈跟踪。没有它,我们只能在黑暗中猜枪声。你想做什么?为什么要调用context.getExternalFilesDir(null)?告诉我们目的,我们可能会更好地瞄准你。另外,日志猫中的堆栈跟踪也会很有帮助。我正在尝试从网上下载一个文件到我设备的外部存储目录中。这将由服务执行,并且应该从应用程序的所有其余部分异步运行。为了做到这一点,我假设我需要连接并访问外部存储。我将
上下文
传递给准备
下载管理器的
可运行
。请求
执行这些操作。我首先检查了外部存储,但在这里它失败了,即使
Environment.getStorageState()
有效。我在2.3.3和4.0上也看到了这个问题。似乎设备进入了一种状态,它将继续返回null(或者可能是空字符串),只有硬重置才能修复它。事实上,它大部分时间都能工作,这让我觉得我的代码/清单是可以的。这可以工作,但有时会在清除我的应用程序数据后返回。这也是我想到的答案。我简直不敢相信这不是一个更常见的问题,也不是一个更容易访问的地方。@ToddPainton我没有遇到这个问题-也许你没有在“设置”中设置开发人员选项?我使用安卓4.04API15。三星S2。哦,不,设定好了。最终我的解决方案是什么?团结。我再也不能忍受原生android编程了。作为一个额外的优点?我可以将相同的代码编译到苹果。我很惊讶有三种不同的根本原因。这是最奇怪的事情,我把权限移到了应用程序行之前,现在它可以工作了。中间确实重新启动了,但已经重新启动了很多次。谢谢。我面临着完全相同的问题,这个解决方案为我解决了这个问题,Thnx!
private boolean canWriteEx () {

    String state = Environment.getExternalStorageState ();

    if (state.equals (Environment.MEDIA_MOUNTED)) {
        Log.i (TAG, "Can write to external directory: "
                + context.getExternalFilesDir (null).getAbsolutePath ());
        return true;
    } else {
        Log.i (TAG, "Cannot write to external directory: "
                + context.getExternalFilesDir (null).getAbsolutePath ());
        return false;
    }
}