简体   繁体   中英

android phonegap FileTransfer.download() recieving error code 3

I am trying to use FileTransfer.download() but seem to get "error code 3" no matter what I try. Any help is greatly appreciated.

I am using cordova 2.1 and zend studio 10 which is built on eclipe to build out my manifest and apk files.

Below is my code

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

Below is my cordova xml file

<?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>

and my 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>

I have also tried setting android:debuggable="true" in my application tag

Any help is greatly appreciated

So I finally found the problem. It was a CORS issues

I had the correct setting in my cordova config.xml

<access origin=".*" />

However, when Zend studio built out my android project this setting did not get transferred over to my res/xml/config.xml

After adding the access origin line in that file everything started working as expected.

i solved this error. Need to add 'true' parameter after fail callback function, see below code and cheer guys.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM