一、安装可检测 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) => {
/* 未安装,请编写提示代码或跳转下载 */ }
);
}
}
网友评论