使用plus 获取了已安装应用列表,图标如何转换呀?
- 发布:2021-11-26 14:50
- 更新:2021-12-07 10:34
- 阅读:674
zzhi_bo (作者) - 前端小次
var apkKist = []; // 这个是应用列表
plus.android.importClass('java.util.ArrayList');
plus.android.importClass('android.content.pm.PackageInfo');
plus.android.importClass('android.content.pm.PackageManager');
var ApplicationInfo = plus.android.importClass('android.content.pm.ApplicationInfo');
var MainActivity = plus.android.runtimeMainActivity();
var PackageManager = MainActivity.getPackageManager();
var pinfo = plus.android.invoke(PackageManager, 'getInstalledPackages', 0)
plus.android.importClass('android.graphics.drawable.BitmapDrawable');
var BitmapFactory = plus.android.importClass("android.graphics.BitmapFactory");
var Base64 = plus.android.importClass("android.util.Base64");
var Bitmap = plus.android.importClass('android.graphics.Bitmap');
var ByteArrayOutputStream = plus.android.importClass("java.io.ByteArrayOutputStream");
if (pinfo != null) {
for (var i = 0; i < pinfo.size(); i++) {
//PackageInfo{4b45699f9d com.tencent.mobileqq}
var pkginfo = pinfo.get(i);
var issysapk = ((pkginfo.plusGetAttribute("applicationInfo").plusGetAttribute("flags") &
ApplicationInfo.FLAG_SYSTEM) != 0) ? true : false
if (issysapk == false) {
const apkinfo = {
name: pkginfo.plusGetAttribute("applicationInfo").loadLabel(PackageManager)
.toString(),
packageName: pkginfo.plusGetAttribute("packageName"),
// versionName: pkginfo.plusGetAttribute("versionName"),
// versionCode: pkginfo.plusGetAttribute("versionCode"),
appIco:pkginfo.plusGetAttribute("applicationInfo").loadIcon(PackageManager)
}
var bimp=apkinfo.appIco.getBitmap();
try{
var baos = new ByteArrayOutputStream();
bimp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
baos.flush();
baos.close();
var bitmapBytes = baos.toByteArray();
var result = "data:image/jpeg;base64,"+Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
apkinfo.img=result;
}catch(e){
}
apkKist.push(apkinfo);
};
};
};