PhoneGap 3.3文件插件在Android上没有与我合作,我尝试了getFile和getDirectory,并继续给我一个例外
02-20 12:24:34.997: W/System.err(32109): java.net.MalformedURLException: No installed handlers for this URL
02-20 12:24:34.997: W/System.err(32109): at org.apache.cordova.file.FileUtils.getFile(FileUtils.java:684)
02-20 12:24:35.007: W/System.err(32109): at org.apache.cordova.file.FileUtils.access$5(FileUtils.java:679)
02-20 12:24:35.007: W/System.err(32109): at org.apache.cordova.file.FileUtils$16.run(FileUtils.java:349)
02-20 12:24:35.017: W/System.err(32109): at org.apache.cordova.file.FileUtils$24.run(FileUtils.java:473)
02-20 12:24:35.017: W/System.err(32109): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-20 12:24:35.017: W/System.err(32109): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-20 12:24:35.017: W/System.err(32109): at java.lang.Thread.run(Thread.java:841)
JavaScript代码
downloadAgendaPage = function () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
console.log("Emaish: FileSystem Requested");
console.log("Emaish: fileStream.name = " + fileSystem.name);
console.log("Emaish: fileStream.root.name = " + fileSystem.root.name);
fileSystem.root.getFile("text.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log("Emaish: File Gotten");
var uri = encodeURI("http://****/data/MYOEB2013_Agenda.ics");
console.log("Emaish: uri:" + uri);
var sPath = fileEntry.fullPath.replace("text.txt", "Agenda.ics");
console.log("Emaish: sPath:" + sPath);
fileEntry.remove();
var fileTransfer = new FileTransfer();
fileTransfer.download(
uri,
sPath,
function (theFile) {
console.log("download complete: " + theFile.toURI());
//showLink(theFile.toURI());
alertify.alert("Agenda downloaded to " + theFile.toURI());
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
}
);
}
Console.log结果
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(59)] "Emaish: FileSystem Requested", source: file:///android_asset/www/js/agenda.js (59)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(60)] "Emaish: fileStream.name = persistent", source: file:///android_asset/www/js/agenda.js (60)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(61)] "Emaish: fileStream.root.name = ", source: file:///android_asset/www/js/agenda.js (61)
答案 0 :(得分:1)
这个奇怪错误的原因是我手动更新了cordova-plugins.js文件并手动添加了插件js文件,因为它们没有自动添加。 为什么他们没有自动添加?因为我做错了..
答案是不构建然后添加插件,而是添加插件然后构建然后用你的文件替换www文件。
答案 1 :(得分:0)
在phonegap 3.3.0中读取目录结构时发生了变化。
我遇到了类似的问题,我必须使用带有window.resolveLocalFileSystemURL()的fullPath来读取目录中的所有文件。
我尝试使用fileEnteries.fullPath来获取绝对路径,但是它显示了'/'(root)作为早期版本,它曾经是'file:///'。
* 使用条目[i] .toURL()来获取绝对路径而不是fileEnteries.fullPath *
for (var i = 0; i < entries.length; i++) {
//Adding into Store for my example
data.push({
fileName : entries[i].name,
isDirectory : entries[i].isDirectory,
fullPath : entries[i].toURL() //instead of entries[i].fullPath
});
}
以后用于 window.resolveLocalFileSystemURL(entries [i] .toURL(),success,failuere);
它对我有用!!