简体   繁体   English

IONIC 3 无法使用@ionic-native/file-opener 在 Android 中打开 PDF 文件

[英]IONIC 3 Can't not open PDF file in Android with @ionic-native/file-opener

error {"status":9,"message":"Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://io.ionic.starter.fileOpener2.provider/files/1600942455974.pdf typ=application/pdf flg=0x3 }" error {"status":9,"message":"Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://io.ionic.starter.fileOpener2.provider/files /1600942455974.pdf 类型=应用程序/pdf flg=0x3 }"

"@ionic-native/document-viewer": "^4.20.0", "@ionic-native/file": "^4.20.0", "@ionic-native/file-opener": "^4.20.0", "@ionic-native/file-transfer": "^4.20.0", "@ionic-native/splash-screen": "4.20.0", "@ionic-native/status-bar": "4.20.0", “@ionic-native/document-viewer”:“^4.20.0”,“@ionic-native/file”:“^4.20.0”,“@ionic-native/file-opener”:“^4.20.0 ", "@ionic-native/file-transfer": "^4.20.0", "@ionic-native/splash-screen": "4.20.0", "@ionic-native/status-bar": "4.20 .0",

Code :代码 :

let fackNama = Date.now();
      this.file.copyFile(path, 'help_guide.pdf', this.file.dataDirectory, `${fackNama}.pdf`).then(result => {
        this.fileOpener.open(result.nativeURL, 'application/pdf').then(() => console.log('File is opened'))
        .catch(e => console.log(JSON.stringify(e)));
      });

How to fix this issue?如何解决这个问题?

This error is thrown when the plugin is unable to find an application to open the specified file in. Since most phones come with a file opener in-built, I'm assuming this app is being used in a user profile that does not include a file opener.当插件无法找到打开指定文件的应用程序时会引发此错误。由于大多数手机都内置了文件打开器,我假设此应用程序正在使用的用户配置文件中不包含文件打开器。

You can try using the showOpenWithDialog() on the plugin.您可以尝试在插件上使用showOpenWithDialog() This method isn't included in Ionic Native however但是,此方法不包含在 Ionic Native 中

I'm using this way, you can use it我用这种方式,你可以用

downloadFile(url: string) {
    
    if (this.platform.is('ios')) {
      this.pdfFileOpen(url, this.file.syncedDataDirectory);
    } else {
      this.pdfFileOpen(url, this.file.dataDirectory);
    }
   
  }

  pdfFileOpen(url, fileDir) {

    const pdfFileName = url.split('/')[4]
    this.file.createDir(fileDir, 'FolderName', true)
    .then(resp => {
      
      const fileTransfer: FileTransferObject = this.transfer.create();
      fileTransfer.download(url, resp.toURL() + pdfFileName)
        .then(entry => {
          
          this.fileOpener.showOpenWithDialog(resp.toURL() + pdfFileName, 'application/pdf');
        
        });

      });
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 10 @ionic-native/file-transfer /file-opener 不工作 - Android 10 @ionic-native/file-transfer /file-opener not working Ionic Native File Opener 插件不会在 Android 中使用默认应用程序打开 .pdf 文件 - Ionic Native File Opener plugin won't open .pdf files with default app in Android 无法安装Ionic-Native File插件 - Cannot install Ionic-Native File plugin 运行 ionic cordova add platform android 后的 Ionic 3,我的 ionic-native/file,filepath,transfer 发生错误 - Ionic 3 after running ionic cordova add platform android, error occurs to my ionic-native/file,filepath,transfer 使用 @ionic-native/file/ngx 从 Android 下载文件夹读取文本文件时出现问题 - Android 11 - Issue when reading text file from Android Download folder with @ionic-native/file/ngx - Android 11 ionic 4 - 使用 @ionic-native/file/ngx/cordova-plugin-file 访问 iOS 文件 - ionic 4 - iOS file access with @ionic-native/file/ngx/cordova-plugin-file Ionic (v3.19.1):使用 ionic-native/file 创建的文件不可见 - Ionic (v3.19.1): Created file is not visible using ionic-native/file @ ionic-native /打印机不起作用 - @ionic-native/printer is not working @ ionic-native / push的离子问题 - ionic issues with @ionic-native/push 如何使用ionic 3 @ ionic-native / http在本地HTTP中传递FormData? - How can pass FormData in native HTTP with ionic 3 @ionic-native/http?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM