[英]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.