0

Im using FileOpener in ionic2 native

Doc here.

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.

iehrlich
  • 3,572
  • 4
  • 34
  • 43
ADiL
  • 367
  • 4
  • 17

1 Answers1

1

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');}
        });
  }

}
C.OG
  • 6,236
  • 3
  • 20
  • 38
  • Ooh Thank you so much... I'll try it. – ADiL Nov 30 '16 at 12:25
  • Opss I got this error : 1 038429 error EXCEPTION: Uncaught (in promise): [object Object] 2 038438 error ORIGINAL STACKTRACE: 3 038443 error Error: Uncaught (in promise): [object Object] at s (http://192.168.1.37:8100/build/polyfills.js:3:8568) at http://192.168.1.37:8100/build/polyfills.js:3:8318 at Object.cordova.callbackFromNative (http://192.168.1.37:8100/cordova.js:295:52) – ADiL Nov 30 '16 at 12:34
  • at processMessage (http://192.168.1.37:8100/cordova.js:1119:17) at processMessages (http://192.168.1.37:8100/cordova.js:1142:9) at t.invoke (http://192.168.1.37:8100/build/polyfills.js:3:13422) at Object.inner.inner.fork.onInvoke (http://192.168.1.37:8100/build/main.js:3:25181) at t.invoke (http://192.168.1.37:8100/build/polyfills.js:3:13373) at e.run (http://192.168.1.37:8100/build/polyfills.js:3:10809) at http://192.168.1.37:8100/build/polyfills.js:3:8911 – ADiL Nov 30 '16 at 12:34
  • Thats a different error. It means that their is something wrong with the code, but you don't have an error call back. I will update the answer with a callback – C.OG Nov 30 '16 at 13:58
  • I have edited the answer to include the error response. Your error will persist, but you will have more information for debug – C.OG Nov 30 '16 at 14:02
  • thanks for your effort ... yeah that one now gives a callback you're right ... and now the callback said File Not Found ... and after I made researches on google I didn't find how to open a file from within the /assets folder of the app it self and not from file system folder like /Download or anyting. is that even possible ? here is the project hierarchy : AppFolder -www -src --- assets -------app.apk ---pages ------installHelper ----------installHelper.ts ----------installHelper.htm ----------installHelper.scss --- app --- theme . . . -platforms -hooks . . . – ADiL Nov 30 '16 at 14:10
  • Since that is a different problem, could you mark this answer as accepted and raise another question and I'll try help you there – C.OG Nov 30 '16 at 14:14
  • but quickly, try without the first '/' so .. FileOpener.open('assets/app.apk', '... – C.OG Nov 30 '16 at 14:15
  • I did it and it gives : 1 678771 log status : 9 2 678772 log error : File not found – ADiL Nov 30 '16 at 14:22
  • Ok, accept this answer for your original issue and make a new question – C.OG Nov 30 '16 at 14:29
  • Done Thank you here is the new question http://stackoverflow.com/questions/40891028/open-a-file-within-the-app-folder-with-fileopener-ionic2 – ADiL Nov 30 '16 at 14:34