uniapp获取本机所有应用包名
huoqu(e){
uni.showLoading({
title: '获取中'
});
const main = plus.android.runtimeMainActivity();
let pManager = plus.android.invoke(main, 'getPackageManager');
let pInfo = plus.android.invoke(pManager, 'getInstalledPackages', 0);
let total = plus.android.invoke(pInfo, 'size');
let packName = '';
let appName = '';
let obj = null;
// 遍历获取包名和应用名称
var arr=[]
for (let i = 0; i < total; i++) {
// 获取包名
packName = plus.android.getAttribute(plus.android.invoke(pInfo, 'get', i), 'packageName');
// 获取包名对应的应用名
obj = plus.android.invoke(pManager, 'getApplicationInfo', packName, 0);
appName = plus.android.invoke(pManager, 'getApplicationLabel', obj);
console.log(packName, appName);
arr.push({
appName:appName,
packName:packName
})
if(i==total-1){
uni.hideLoading()
}
}
this.arr=arr;
},