Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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 phonegap FileTransfer.download()接收错误代码3_Android_Cordova_File Transfer - Fatal编程技术网

android phonegap FileTransfer.download()接收错误代码3

android phonegap FileTransfer.download()接收错误代码3,android,cordova,file-transfer,Android,Cordova,File Transfer,我正在尝试使用FileTransfer.download,但无论我如何尝试,似乎都会得到错误代码3。非常感谢您的帮助 我正在使用cordova 2.1和zend studio 10构建在eclipe上,以构建我的清单和apk文件 下面是我的代码 var fileTransfer = new FileTransfer(); fileTransfer.download( "http://www.w3.org/2011/web-apps-ws/papers/Nitobi

我正在尝试使用FileTransfer.download,但无论我如何尝试,似乎都会得到错误代码3。非常感谢您的帮助

我正在使用cordova 2.1和zend studio 10构建在eclipe上,以构建我的清单和apk文件

下面是我的代码

var fileTransfer = new FileTransfer();
    fileTransfer.download(
            "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
            "file:///sdcard/theFile.pdf",
        function(entry) {
            alert("download complete: " + entry.fullPath);
        },
        function(error) {
            alert("download error source " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
        });
下面是我的cordova xml文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.phonegap.example" version="1.0.0" versionCode="1">
  <name>App</name>
  <feature name="http://api.phonegap.com/1.0/file"/>
  <feature name="http://api.phonegap.com/1.0/network"/>
  <feature name="http://api.phonegap.com/1.0/device"/>
  <access origin=".*" />
</widget>
还有我的android manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.phonegap.example"
    android:versionCode="1"
    android:versionName="1.0.0" 
    >



    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true" />

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:configChanges="orientation|keyboardHidden"
            android:name=".PhonegapActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
我还尝试在我的应用程序标记中设置android:debuggable=true


非常感谢您的帮助,所以我终于找到了问题所在。 这是一个CORS问题

我在cordova config.xml中有正确的设置

<access origin=".*" />
然而,当Zend studio构建我的android项目时,这个设置并没有转移到我的res/xml/config.xml

<access origin=".*" />

在该文件中添加访问起始行后,一切都开始按预期工作。

因此我最终发现了问题。 这是一个CORS问题

我在cordova config.xml中有正确的设置

<access origin=".*" />
然而,当Zend studio构建我的android项目时,这个设置并没有转移到我的res/xml/config.xml

<access origin=".*" />

在该文件中添加访问原点行后,一切都按预期开始工作。

我解决了此错误。需要在回调函数失败后添加'true'参数,请参阅下面的代码和示例

fileTransfer.download(
            "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
            "file:///sdcard/theFile.pdf",
        function(entry) {
            alert("download complete: " + entry.fullPath);
        },
        function(error) {
            alert("download error s`enter code here`ource " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
        }, true);

我解决了这个错误。需要在回调函数失败后添加'true'参数,请参阅下面的代码和示例

fileTransfer.download(
            "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
            "file:///sdcard/theFile.pdf",
        function(entry) {
            alert("download complete: " + entry.fullPath);
        },
        function(error) {
            alert("download error s`enter code here`ource " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
        }, true);

如何将其添加到电容器项目中?如何将其添加到电容器项目中?