0.0.6 • Published 4 years ago

@modea/capacitor-app-launcher v0.0.6

Weekly downloads
34
License
MIT
Repository
bitbucket
Last release
4 years ago

Capacitor App Launcher

TOC

Install

npm i @modea/capacitor-app-launcher

Usage

In your src directory

import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { Plugins } from '@capacitor/core';

const { Browser, AppLauncher } = Plugins;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
  consumerAppIdentifier: string;
  consumerAppStoreUrl: string;

  constructor(private platform: Platform) {}

  ngOnInit(): void {
    this.setBundleIdAndStoreUrl(this.platformIsAndroid());
  }

  setBundleIdAndStoreUrl(isAndroid: boolean) {
    if (isAndroid) {
      this.consumerAppIdentifier = Constants.CONSUMER_APP.android.bundleId;
      this.consumerAppStoreUrl = Constants.CONSUMER_APP.android.storeUrl;
    } else {
      this.consumerAppIdentifier = Constants.CONSUMER_APP.iOS.appUrl;
      this.consumerAppStoreUrl = Constants.CONSUMER_APP.iOS.storeUrl;
    }
  }
  platformIsAndroid() {
    return this.platform.is('android');
  }

  openConsumerApp() {
    AppLauncher.launchForeignApp({ identifier: this.consumerAppIdentifier })
      .then((pluginResponse) => {
        console.log('Response', pluginResponse);
        if (pluginResponse.didLaunch) {
          console.log('Opened app');
        } else {
          console.log('Did not open app');
        }
      })
      .catch((reason) => {
        console.log('Call rejected', reason);
      });
  }
}

Android

Make sure to add the plugin class in the MainActivity.java file

import com.modea.plugins.capacitor.app.launcher.AppLauncher;
.
.
.

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(AppLauncher.class);
    }});

iOS

Make sure to add urls you want to open to your whitelist

    <key>LSApplicationQueriesSchemes</key>
    <array>
		<string>urlscheme-you-want-to-open</string>
		<string>another-one</string>
	</array>
0.0.6

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago