Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> packages = pm.queryIntentActivities(intent,
PackageManager.PERMISSION_GRANTED);
for (ResolveInfo ap : packages) {
BitmapDrawable drawableIcon = null;
Bitmap icon = null;
try {
// try to get the hdpi icon
drawableIcon = (BitmapDrawable)mContext.getApplicationContext()
.createPackageContext(ap.activityInfo.packageName,Context.CONTEXT_IGNORE_SECURITY)
.getResources().getDrawableForDensity(
/*
* some classes have its own icon
*/
ap.activityInfo.icon == 0 ? ap.activityInfo.applicationInfo.icon
: ap.activityInfo.icon, DisplayMetrics.DENSITY_HIGH);
} catch (Exception e) {
drawableIcon = (BitmapDrawable)ap.loadIcon(pm);
} finally {
icon = drawableIcon.getBitmap();
}
}
Android 拿到所有 Launcher app icon
最新推荐文章于 2021-05-27 08:31:15 发布