一、安裝可檢測 APP 是否安裝的插件? (App Availability - Ionic Documentation)
二孕惜、安裝可跳轉app的插件Web intent? (Web Intent - Ionic Documentation)
注意Web intent插件版本:
For Android X Support please use version >=?2.x.x
For Android Support Library please use version?1.3.x
三丰榴、引入到 app.module.ts
import?{?AppAvailability?}?from?'@ionic-native/app-availability';
import?{?WebIntent?}?from?'@ionic-native/web-intent';
providers: [
? ? WebIntent,AppAvailability
]
四、以 Home.ts 為例
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { AppAvailability } from '@ionic-native/app-availability';
import { Platform } from 'ionic-angular';
@IonicPage()
@Component({
? ? selector: 'page-Home',
? ? templateUrl: 'Home.html',
})
export class Home {
? ? constructor(
? ? ? ? public navCtrl: NavController,
? ? ? ? public navParams: NavParams,
? ? ? ? private iab: InAppBrowser,
? ? ? ? private appAvailability: AppAvailability,
? ? ? ? private platform: Platform
? ? ) { }
? ? ionViewDidLoad() {
? ? ? ? var app = '';
? ? ? ? if (this.platform.is('ios')) {
? ? ? ? ? ? app = 'xxx://';? ? ? /* Scheme URL */
? ? ? ? } else if (this.platform.is('android')) {
? ? ? ? ? ? app = '安卓包名';? ? /安卓包名 */
? ? ? ? }
this.appAvailability.check(app)
.then(
? ? ? ? ? ? ?(yes: boolean) => {
? ? ? ? ? ? ? /* 已經安裝,跳轉app */
? ? ? ? ? ? ? ? ?const?options?=?{
? ? ? ? ? ? ? ? ? ? ? ? ?action:?"com.darryncampbell.cordova.plugin.intent.ACTION",
? ? ? ? ? ? ? ? ? ? ? ? ?type:?'application/vnd.android.package-archive',
? ? ? ? ? ? ? ? ? ? ? ? ?package:?'安卓包名',
? ? ? ? ? ? ? ? ? ? ? ? ?component:?{?package:?"安卓包名",?class:?"安卓包名.MainActivity"?}
????????????????????????????????????????????????????};
? ? ? ? ? ? ? ? ?this.webIntent.startActivity(options);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?};
? ? ? ? ? ? ? (no: boolean) => {
? ? ? ? ? ? ? ? ? /* 未安裝,請編寫提示代碼或跳轉下載 */? ? ? ? ? ? }
? ? ? ? ?);
? ? }
}