2013-02-08 55 views
2

我想使用FileTransfer.download(),但似乎得到「錯誤代碼3」,無論我嘗試。任何幫助是極大的讚賞。android phonegap 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); 
     }); 

下面是我的科爾多瓦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:可調試=在我的應用程序標籤中爲「true」

任何幫助,非常感謝

回答

3

所以我終於找到了問題。 這是一個CORS發出

我有正確的設置在我的科爾多瓦config.xml中

<access origin=".*" /> 

然而,當Zend Studio的內置了我的Android項目該設置並不會轉移到我的RES/XML /config.xml

在該文件中添加訪問原始行後,所有事情都按預期開始工作。

+0

保存我的日子+1 – 1Mayur

0

我解決了這個錯誤。在失敗回調函數後需要添加'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); 
相關問題