Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch external app from an ionic4 app

My app is under Ionic 4 for android and I have to open/run/launch external app (for exemple com.google.android.youtube or com.sygic.truck) -> for instance, any installed app.

I tested many options without any success :

InAppBrowserModule (using application://my.package.name).

Cordova plugin lampaa (I didn't find any ways to use it under angular/ts app type).

I tried also webIntent using package option and action option calling the main Activity.


For InAppBrowserModule, i'm stuck with the http:// protocole appended before my app url.

For Lampaa, i'm stuck with the undefined startApp (even after following other threads suggestions).

And for webIntent, I don't think that it's relevent for my issue.

Any suggestions ?

Thanks in advance !


[EDIT]

I finally make it works !

You can use one of those 2 lines :

 this.iab.create('android-app://com.google.android.youtube',"_system");

 window.open('android-app://com.google.android.youtube',"_system");

You can replace com.google.android.youtube by any application package name !

like image 861
Lucas Avatar asked Feb 11 '19 14:02

Lucas


3 Answers

You can check if the user is on Android, have the app installed and later open it as follow:

constructor(
   private platform: Platform,               // from 'ionic-angular'
   private appAvailability: AppAvailability, // from '@ionic-native/app-availability'
   private iab: InAppBrowser,                // from '@ionic-native/in-app-browser'
) {}

openYoutube() {
   const package = "com.google.android.youtube"
   if(this.platform.is('android')) {
      this.appAvailability.check(package)
         .then(()=> {
            this.iab.create('android-app://'+package, '_system', 'location=yes')
         })
         .catch(()=> {
            // not installed
         )
   } else {
      // not on Android
   }
}
like image 174
Alejandro Silva Avatar answered Oct 10 '22 13:10

Alejandro Silva


For ionic 4 we can use

ionic cordova plugin add cordova-plugin-app-launcher
npm install @ionic-native/app-launcher
like image 43
Atul Avatar answered Oct 10 '22 14:10

Atul


You can use the following cordova plugin to check if other apps are installed and launch them.

ionic cordova plugin add cordova-plugin-app-launcher

npm install @ionic-native/app-launcher

Simple Cordova plugin to see if other apps are installed and launch them.

like image 28
Tek choudhary Avatar answered Oct 10 '22 14:10

Tek choudhary