|
开发过程中曾遇到过快应用调起APP需求,现分享给大家,希望大家多多指教共同进步1:先检查是否有相关应用,应用的包名可以去百度搜索,
2:利用prompt的上下文进行选择调起哪一个,话不多说 上代码:
import pkg from '@system.package'
import router from '@system.router'
import prompt from '@system.prompt';
export default {
data: {
mapAppList: [],
mapPackage: [
{
packageName: "com.baidu.BaiduMap",
name: "百度地图"
},
{
packageName: "com.taobao.taobao",
name: "淘宝"
},
{
packageName: "com.mfw.roadbook",
name: "马蜂窝旅游"
}
],
},
onInit() {
this.checkMapApp()
},
// 检测是否有先关应用
checkMapApp() {
this.mapPackage.map(item => {
pkg.hasInstalled({
package: item.packageName,
success: result => {
if (result.result) {
this.mapAppList.push(item)
}
}
}
})
},
//点击测试
Click() {
prompt.showContextMenu({
itemList: this.mapAppList.map(item => item.name),
success: (res) => {
switch (this.mapAppList[res.index].name){
case "百度地图" :{
router.push({
uri:"baidumap://map/direction?destination=name:undefined|latlng:undefined,undefined|addr:undefined&coord_type=gcj02&src=andr.powerbank.openAPIdemo&mode=walking"
});
break;
}
case "淘宝" :{
router.push({
uri:"tbopen://m.taobao.com/tbopen/index.html?source=auto&action=ali.open.nav&module=h5&bootImage=0&spm=2014.ugdhh.3234525723.219188-1198-32768&bc_fl_src=growth_dhh_3234525723_219188-1198-32768&materialid=219188&h5Url=https%3A%2F%2Fh5.m.taobao.com%2Fbcec%2Fdahanghai-jump.html%3Fspm%3D2014.ugdhh.3234525723.219188-1198-32768%26bc_fl_src%3Dgrowth_dhh_3234525723_219188-1198-32768"
});
break;
}
case "马蜂窝旅游":{
router.push({
uri:"travelguide://jump?source=ug-lh-aguya_sqhqc_5&url=https%3A%2F%2Fimfw.cn%2Fl%2F112231225"
});
break;
}
default:
break;
}
}
})
}
}
|
|