Cordova文件打开程序无法找到文件

时间:2017-04-15 20:50:55

标签: javascript android cordova pdf

我正在尝试使用cordova-plugin-file-opener2在Cordova中加载pdf。我似乎无法在浏览器或Android上使用它。

这是我的app.js文件:

(function () {

    document.querySelector('#file-button').addEventListener('click', openFile);
    function openFile(){
        console.log('opening file');
        console.log(cordova.file.applicationDirectory);       
        var fileName = 'www/assets/pdf/foo.pdf';
        var pathToFile = cordova.file.applicationDirectory + fileName;
        window.resolveLocalFileSystemURL(pathToFile, function (entry) {
            cordova.plugins.fileOpener2.open(
                entry.toInternalURL(),
                'application/pdf', {
                    error: function (e) {
                        alert.log('Error status: ' + e.status + ' - Error message: ' + e.message);
                    },
                    success: function () {
                        alert.log('file opened successfully');
                    }
                }
            );
        }, function (e) {
            alert('File Not Found');
        });

    }

}());

这是html:

<!DOCTYPE html>
<html>
  <head>
    <script src="cordova.js"></script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>

<p><button id="file-button" class="help-btn">Help</button></p>
<div class='header'><h1>Directory</h1></div>
<div class='search-view'>
    <input class='search-key' type="search" placeholder="Enter name"/>
    <ul class='list employee-list'></ul>
</div>

<script src="lib/jquery.js"></script>
<script src="js/services/memory/EmployeeService.js"></script>
<script src="js/app.js"></script>

</body>
</html>

单击“文件按钮”时,会触发openFile函数 这在控制台中显示了以下内容:

adding proxy for Device  cordova.js:1010:9
adding proxy for File  cordova.js:1010:9
opening file  app.js:6:9
"http://localhost:8000/"  app.js:7:9

警告信息显示'File not found'

App.js位于www --> js foo.pdf位于www --> assets --> pdf

0 个答案:

没有答案