【问题标题】:Cordova File Plugin with InAppBrowser Plugin and File Opener Plugin带有 InAppBrowser 插件和文件打开器插件的 Cordova 文件插件
【发布时间】:2016-11-11 13:14:50
【问题描述】:

我有一个使用 File Plugin 存储的 PDF 文件,但我似乎无法使用 InAppBrowser 或 File Opener Plugin 打开它。我正在使用适用于 Android 的 Visual Studio Emulator KitKat。

这里是 InAppBrowser 插件的代码。 fileEntry.toURL() 方法返回“file:///data/data/com.ionicframework.ionicblankapp/cache/Sample.pdf”。

但是,InAppBrowser 总是显示一个空白页面。

window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) {
      dirEntry.getFile(fileName, { create: true, exclusive: false },
           function (fileEntry) {
                fileEntry.createWriter(
                     function (fileWriter) {
                         fileWriter.onwriteend = function (e) {
                             var ref = cordova.InAppBrowser.open(fileEntry.toURL(), '_blank');
                          };
                          fileWriter.write(fileBlob);
                });
       });
 });

对于文件打开器插件,我收到“9”的错误状态和此消息

未找到活动:未找到处理 Intent 的活动 { act=android.intent.action.VIEW dat=file:///data/data/com.ionicframework.ionicblankapp/cache/Sample.pdf typ=application/pdf flg=0x4000000 }"

下面是 File Opener Plugin 的代码。

    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) {
                            dirEntry.getFile(fileName, { create: true, exclusive: false },
                                function (fileEntry) {
                                    fileEntry.createWriter(
                                        function (fileWriter) {
                                            fileWriter.onwriteend = function (e) {    
cordova.plugins.fileOpener2.open(fileEntry.toURL(), 'application/pdf', {
                                                success: function () {
                                                    //success
                                                },
                                                error: function (e) {
                                                    alert(e);
                                            });
                                            };
                                            fileWriter.write(fileBlob);
                                        });
                                });
                        });

目前,我不确定自己缺少什么。任何帮助将不胜感激。

【问题讨论】:

标签: javascript android cordova ionic-framework


【解决方案1】:

尝试更改此行

 var ref = cordova.InAppBrowser.open(fileEntry.toURL(), '_blank');

 var ref = cordova.InAppBrowser.open(fileEntry.toURL(), '_system');

【讨论】:

  • 我试过这个,InAppBrowser 现在甚至没有出现。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多