gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:05:34 24 4
gpt4 key购买 nike

我正在尝试使用 FileTransfer.download(),但无论我尝试什么,似乎都会收到“错误代码 3”。任何帮助是极大的赞赏。

我正在使用 cordova 2.1 和基于 eclipe 构建的 zend studio 10 来构建我的 list 和 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

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

关于android phonegap FileTransfer.download() 收到错误代码 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14765085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com