使用Cordova FileOpener2和其他许多插件,如Cordova File、Cordova FileTransfer..我在Android中找不到我的本地PDF位置。
这个文件在www/offline-files/目录中,当我在iOS (使用window.open(encodeURI('offline-files/myFile.pdf'), '_blank');)中打开它时,它工作得很好!如果我在Android上尝试同样的事情,它不起作用。例如,我的许多尝试中的一个:
function getPath()
{
// Get local path for Cordova
var path = window.location.pathname;
path = path.substr(path, path.length - 10);
return 'file://' + path;
}
cordova.plugins.fileOpener2.open(
getPath() + 'offline-files/myFile.pdf',
'application/pdf',
{
error: function (e)
{
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success: function ()
{
console.log('file opened successfully');
}
}
);科尔多瓦将日志返回给我:"Error status: 9 - Error message: File not found"
还有一个奇怪的错误: Cordova file plugin返回一个在经典目录中找不到的错误文件:
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory,
function (dir)
{
/** SOME CODE **/
}
);发布于 2015-04-16 10:34:29
您使用的是什么版本的Cordova?在任何情况下,我都不会硬编码文件路径并从LocalFileSystem对象中获取它。
var fs;
function fsSuccess(fileSystem)
{
fs = fileSystem;
}
function fsFail(event)
{
console.log(event.target.error.code);
}
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess, fsFail); 然后通过以下方式访问根路径:
fs.root.toURL() + "yourfilename"希望这能有所帮助!
https://stackoverflow.com/questions/28414344
复制相似问题