@modea/capacitor-app-launcher
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

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>

Readme

Keywords

Package Sidebar

Install

npm i @modea/capacitor-app-launcher

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

117 kB

Total Files

41

Last publish

Collaborators

  • joel.cook
  • brian.walter
  • kory.koch
  • jeb.schiefer
  • chris.guilliams
  • modea.integrator
  • kristen.alexander
  • masonturbyfill
  • corey.caldwell
  • brendanholly
  • theheumanmodean