大家好,欢迎来到IT知识分享网。
权限
<uses-permission android:name=”android.permission.QUERY_ALL_PACKAGES” />
获取安装的应用、icon图
var queryIntentActivities = mutableListOf<ResolveInfo>()
val intent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
queryIntentActivities =
packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
} else {
queryIntentActivities = packageManager.queryIntentActivities(intent, 0)
}
queryIntentActivities.forEach {
val bitmap = it.loadIcon(packageManager).toBitmap()
val size = bitmap.width * bitmap.height
val baos = ByteArrayOutputStream(size)
// 设置位图的压缩格式,质量为100%,并放入字节数组输出流中
// 设置位图的压缩格式,质量为100%,并放入字节数组输出流中
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos)
val imagedata = baos.toByteArray()
val icon: String = Base64.encodeToString(imagedata, Base64.DEFAULT)
val appName = it.loadLabel(packageManager).toString()
val appPackageName = it.activityInfo.applicationInfo.packageName
// com.tal.znxx.log.KLog.d(TAG,icon);
com.tal.znxx.log.KLog.d(TAG,appName);
com.tal.znxx.log.KLog.d(TAG,appPackageName);
}
根据报名跳转:
Handler(this.mainLooper).postDelayed({
try {
val packageName = “com.android.calculator”;
val intent = packageManager.getLaunchIntentForPackage(packageName)
startActivity(intent);
}catch (e:Exception){
ToastUtils.showCenter(“功能开发中,敬请期待”)
}
}, 2000)
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/67340.html