在使用文件传输插件的PhoneGap 3.3 android应用程序中,这是getFile方法的主体
private JSONObject getFile(String baseURLstr, String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
try {
LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
}
return fs.getFileForLocalURL(inputURL, path, options, directory);
} catch (IllegalArgumentException e) {
throw new MalformedURLException("Unrecognized filesystem URL");
}
}
调用
时,Filesystem fs始终为nullfileSystem.root.getFile('text.txt', { create: true, exclusive: false }, function (fileEntry) {}, fail);
或
fileSystem.root.getDirectory('newDir', { create: true, exclusive: false }, function (parent) {}, fail);
这是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)
因此抛出了新的MalformedURLException("没有为此URL安装处理程序");
答案 0 :(得分:0)
问题在于我添加插件并构建我的应用程序的方式,您需要在添加插件后构建您的应用程序,以便将插件js文件正确复制到www文件夹并更新cordova_plugins.js