Im我的头撞在我的桌子上,因为我似乎找不到任何可行的答案。科尔多瓦6.3.1下载PDF并用FileSystem,FileTransfer和FileOpener2打开
我想下载PDF到本地存储的Android设备,然后在外部阅读器中打开它,因为Android无法在浏览器中显示PDF。对于iOS,我只需使用InAppBrowser插件,它可以很好地工作。我使用科尔多瓦6.3.1。
所以,这是我的代码:
if (cordova.platformId === "android") {
var remoteFile = url;
var localFileName = "tmp.pdf";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
//var fileSystemRoot = cordova.file.dataDirectory; Does not work...
var fileSystemRoot = fileSystem.root.toURL()
console.log(cordova.file.dataDirectory);
var ft = new FileTransfer();
ft.download(remoteFile,
fileSystemRoot + "tmp.pdf", function(entry) {
cordova.plugins.fileOpener2.open(
entry.toURL(),
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message + ' - URL: ' + messageObj.url);
},
success : function() {
console.log('file opened successfully');
console.log(fileSystemRoot);
console.log(entry.toURL());
}
}
);
}, function(error) {
console.log("Error in downloading");
console.log(error);
});
}, function(error) {
console.log("Error in requesting filesystem");
console.log(error);
});
}
我曾尝试吨不同的东西。 fileSystem.root.fullpath,fileSystem.root.toURL(),fileSystem.root.nativeURL,但我总是会看到与设备不匹配的路径。我总是得到下载成功的消息,Adobe Reader会弹出,但表示该文件不可读。对我来说并不奇怪,因为它给我的路径是这样的:
file:///data/data/ch.novalogix.novalib/files/files
这可能根本不是真的?我搜索整个系统的上传文件,但我不认为它的下载。我想我总是得到一个错误的路径...
任何想法? 在此先感谢!
本来不错的downvoter告诉我什么是错误的这个问题... –