我尝试实现以下行为:
从外部位置下载文件
在本地保存
打开它
文件打开器插件似乎是完美的匹配,我使用了(打开远程文件)中的一个示例:https ://plugins.telerik.com/cordova/plugin/file-opener
var fileTransfer = new FileTransfer()
fileTransfer.download(
// download from an example pdf
encodeURI('http://rp.delaat.net/2014-2015/p75/report.pdf'),
// save to
'cdvfile://localhost/persistent/test.pdf',
// open the downloaded file
function (entry) {
var file = entry.toURL()
window.cordova.plugins.fileOpener2.open(
file,
'application/pdf',
{
error: function (errorMessage) { console.log(errorMessage) },
success: function () { console.log('succeed') }
}
)
}
)
但是在android上我收到以下错误:
file:///data/user/0/nl.mytestapp/files/files/Download/test.pdf exposed beyond app through Intent.getData()
我正在使用 cordova 来部署我的应用程序。
寻找解决方案让我两手空空。
编辑
错误似乎在于打开文件(fileOpener2),只有下载文件才能正常。