我正在使用Cordova与cordova-plugin-file-transfer和cordova-plugin-file-opener2
我在Android手机上测试。它似乎下载文件,代码报告文件存储在这里(例如entry.toURL()):file:///data/user/0/com.domain.app/cache/downloaded.pdf
但是,如果我浏览文件系统,我找不到此位置来验证文件是否存在。我甚至找不到数据/用户
当调用fileopener2.open时,它会启动pdf应用程序,但报告无法打开文件。
我没有收到任何错误,表明任何事情都失败了。
我想知道它存储的位置是否受到保护,因此无法打开。
感谢任何帮助。
这是我的代码
downloadFile: function () {
window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {
alert('file system open: ' + fs.name);
var url = 'http://www.website.co.uk/test.pdf';
fs.root.getFile('downloaded.pdf', { create: true, exclusive: false }, function (fileEntry) {
app.download(fileEntry, url, true);
}, function () {
alert('onErrorCreateFile');
});
}, function () {
alert('onErrorLoadFs');
});
},
download: function (fileEntry, uri, readBinaryData) {
var fileTransfer = new FileTransfer();
var fileURL = fileEntry.toURL();
fileTransfer.download(
uri,
fileURL,
function (entry) {
alert("download complete: " + entry.toURL());
cordova.plugins.fileOpener2.open(
entry.toURL(),
'application/pdf'
);
},
function (error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
},
null,
{
}
);
},