How to use the plugin : cordova-plugin-file-opener2 in ionic 2


#1

Hy everyone,

First of all, excuse me for my english …

How to use the plugin : cordova-plugin-file-opener2 ?

Because on the web site the import is : import { FileOpener } from ‘@ionic-native/file-opener’;
This import not work on my project … I use Visual Studio Code and it propose to me :

  • import { FileOpener } from ‘ionic-native/dist/es5’;
  • import { FileOpener } from ‘ionic-native/dist/esm’;

And when i use this import, i have an error on open and the error is : “Property ‘open’ does not exist on type 'FileOpener”

My code :

//import { FileOpener } from ‘ionic-native/dist/esm’; --> does not work
//import { FileOpener } from ‘ionic-native/dist/es5’; --> does not work
//import { FileOpener } from ‘ionic-native’; --> does not work
//import { FileOpener } from ‘ionic-native/file-opener’; --> does not work

constructor(public navCtrl: NavController, private fileOpener : FileOpener,) {

}

openPdfFromUrl(){
this.fileOpener.open(‘MY DOCUMENT’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));

}

Help me ! :frowning:

cordova CLI: 6.5.0
Ionic Framework Version: 2.2.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.0


#2

In your code I don’t see:

import { FileOpener } from '@ionic-native/file-opener';

Are you sure that you’ve tried this one? It’s important to note the at symbol in front of ‘ionic-native’.

Also, I assume you’ve gone through the steps to install the plugin?


#3

OHHHH Excuse me yes in my code i tried : import { FileOpener } from ‘@ionic-native/file-opener’;

And it do not worked.
And yes i throught the step on the web site : https://ionicframework.com/docs/native/file-opener/

thank you for your response !! :slight_smile:


#4

Ok thank you @SigmundFroyd
I see i have not execute the line : npm install --save @ionic-native/file-opener

So i tried this line in my shell and i have many warning :
±- UNMET PEER DEPENDENCY @angular/common@2.4.8
±- UNMET PEER DEPENDENCY @angular/core@2.4.8
±- UNMET PEER DEPENDENCY @angular/platform-browser@2.4.8
±- UNMET PEER DEPENDENCY @ionic-native/core@^3.1.0
±- @ionic-native/file-opener@3.4.4
`-- UNMET PEER DEPENDENCY rxjs@5.0.1

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})
npm WARN @angular/router@3.2.4 requires a peer of @angular/core@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of @angular/common@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of @angular/platform-browser@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN @ionic-native/file-opener@3.4.4 requires a peer of @ionic-native/core@^3.1.0 but none was installed.

So i think this is not very important.
But when i check my code this the good params, in my inspector of my browser i have this error :
Uncaught Error: Cannot find module “@ionic-native/core”

Have you got any idee to resolve this problems ?

Thank you.


#5

I’m having the exact same issue. Any news?


#6

You’re having what exact same issue? The post directly above yours is a result of package.json having a bunch of obsolete dependencies.


#7

@rapropos thank you for your reply but my problem is : Uncaught Error: Cannot find module “@ionic-native/core”

and @jrosend i have not found the solution …


#8

Did you try searching the forums for your error message? Does this thread help?


#9

thank you @rapropos
So I create a new project and I export my file in this new project. I have not problem today, I think my last project is corrompt …
Today I test this plugin on 2 device : one device is on Android 5.1 (Galaxy Core Prime) and other device is on Android 7.0 (Samsun Galaxy S6 Edge +) .
When I tried this simple code :
import { FileOpener } from ‘@ionic-native/file-opener’;
constructor(private fileOpener: FileOpener) {}

openPdf(){

this.fileOpener.open(‘storage/emulated/0/cours-exo7.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));

}

I can open the pdf file on the Android 5.1 but on the Android 7.0 the file open and shutdown directly …
IF
Have you got a solution of this problems ?

Thank you in advance community :slight_smile:


#10

I have the same issue.
Does anyone have a solution for this?
Thanks much.


#11

can I open PDF file from external link ?