ADiL ADiL - 4 days ago 6
Android Question

FileOpener in ionic2 native for android

Im using FileOpener in ionic2 native

Doc here : http://ionicframework.com/docs/v2/native/fileopener/

this is my code :

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { FileOpener } from 'ionic-native';

@Component({
selector: 'page-installHelper',
templateUrl: 'installHelper.html'
})
export class InstallHelper {

constructor(public navCtrl: NavController, public fo: FileOpener) {
fo.open('/assets/app.apk', 'application/vnd.android.package-archive');
}

}


but it gives an error says :
Property 'open' does not exist on type 'FileOpener'.


I want to open an apk file from my App.

Answer

With native components, you don't assign it to the constructor.

So your code should look like:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { FileOpener } from 'ionic-native';

@Component({
  selector: 'page-installHelper',
  templateUrl: 'installHelper.html'
})
export class InstallHelper {

  constructor(public navCtrl: NavController) {
        FileOpener.open('/assets/app.apk', 'application/vnd.android.package-archive',
        { 
            error : (e)=> {console.log('Error status: ' + e.status + ' - Error message: ' + e.message);},
            success : ()=> {console.log('file opened successfully');}
        });
  }

}
Comments