【问题标题】:Open any file on ionic在 ionic 上打开任何文件
【发布时间】:2018-09-11 17:32:41
【问题描述】:

我正在尝试使用 ionic 打开文件,因为我使用 documentViewer ionic,但问题是我不会这样做,我的意思是手机有 pdf 查看器,我不会使用文件,但它指示我玩商店并告诉我安装应用程序以查看 pdf。在这里我留下我的代码:

this.documentView.viewDocument(url, type, {});

如你所见,我传递了文件的 URL,然后是类型,最后什么都没有,这是 documentViewer 的选项,告诉我我做得对还是应该使用其他库文件开瓶器

【问题讨论】:

    标签: android angular ionic-framework ionic3


    【解决方案1】:

    如果设备上没有安装查看器,您可以在谷歌文档的帮助下使用In App Browser plugin

    例如:

    constructor(private iab: InAppBrowser) { }
    
    ...
    
    let myUrl = "";
    if (this.platform.is('android')) {
      myUrl = "https://docs.google.com/viewer?url=";
    }
    this.iab.create(myUrl + url, '_blank', 'location=no,hardwareback=no,toolbar=yes,enableViewportScale=yes');
    

    【讨论】:

    • 你能详细说明功能和/或举个例子吗?因为我不太了解那个图书馆
    • 我要打开的文件在设备里面,是这样的吗?
    • 是的,您可以使用本地 URL (cordova.apache.org/docs/en/latest/reference/…)
    • 谢谢,现在我试试,我注意到了
    • 我收到错误 404,我传递的 url 是这样的:file: ///storage/emulated/0/Konecte%20Corp/myarchivo.pdf
    【解决方案2】:

    File Opener Plugin 工作正常。但并非所有 PDF 阅读器都支持在线文档查看。尝试使用File Transfer Plugin下载pdf,然后打开本地存储文件。

    【讨论】:

    • 我已经尝试过使用文件打开器,但它不起作用。它没有检测到pdf的阅读器应用程序,我所做的是下载文件然后我尝试打开它,它还告诉我找不到文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2013-05-05
    相关资源
    最近更新 更多