与https://stackoverflow.com/questions/21044197/download-file-and-store-them-locally-in-sdcard-using-phonegapbuild相关,但这些问题从未得到解答。
关于这个应用程序,我正在编写一个小应用程序,显示一堆pdf,它是使用jquerymobile + phonegap编写的,它是使用phonegap构建服务构建的。
我意识到这个功能无法工作,因为root-Directory不是写任何东西的有效位置。但是,我无法获取应用程序的工作目录,也无法确定使用文档的错误代码1的确切含义。
来自config.xml:
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="permissions" value="none" />
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/device" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />
构建服务告诉我这些插件已经成功添加。
解压缩apk并查看清单也会显示
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
已成功添加。
最后但并非最不重要的是,使用
将phonegap库成功添加到文档中<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
然后只有实际的功能可以归咎于:
function downloadFile(name, url, y,x, canvasid, wrapperid){
alert(name);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
var directoryEntry = fileSystem.root; // to get root path to directory
var rootdir = fileSystem.root;
var fp = rootdir.fullPath;
fp = fp+"/bestsongs/"+name;
alert("downloading: " + url + " to " + fp);
var fileTransfer = new FileTransfer();
alert("downloading: " + url + " to " + fp);
fileTransfer.download(
url,
name,
function(theFile) {
alert("download complete: " + theFile.toURI());
loadPDF(theFile.toURI(), y,x, canvasid, wrapperid);
},function(error) {
alert("error: " + JSON.stringify(error));
}
);
},
function(arg) {
alert("FAIL ON requestFileSystem" + JSON.stringify(arg)); }
);
}
$(function() {
document.addEventListener("deviceready", function() {
alert("deviceready!");
try {
alert(url);
downloadFile(lyrics,url,y,x, 'the-canvas', 'wrapper');
} catch(e) {
alert(e);
}
}, false);
});
使用警报,这是我得到的:
deviceready!
<url> to file (which is right)
the name of the file.
downloading <url> to //bestsongs/<name>
downloading <url> to //bestsongs/<name>
error: {
"code":1,
"source":<url>,
"target":<name>,
"http_status": null,
"body": null
}
我已经调试了好几天,请有人有解决方案。
答案 0 :(得分:2)
嘿,看看我在这里的答案 -
Phonegap - Save image from url into device photo gallery
让我知道。如果还有任何问题。 在config.xml中包含以下内容
对于Android -
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Storage">
<param value="org.apache.cordova.Storage" name="android-package"/>
</feature>
对于IOS -
<plugin name="File" value="CDVFile" />
<plugin name="FileTransfer" value="CDVFileTransfer" />
要检查网络连接是否可用,请在config.xml中添加以下内容 - 在config.xml
中添加plugin.xml和插件名称的权限检查网络连接的插件 对于Android -
<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" />
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
对于IOS -
<plugin name="NetworkStatus" value="CDVConnection" />