我想在我的listview中添加getPackageManager
的应用程序图标。我尝试过类似的东西:
try {
// Icon
Drawable icon = pm.getApplicationIcon(info.processName);
Drawable default_icon = pm.getDefaultActivityIcon();
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
Log.w("LABEL", "Name" + c.toString());
String pName = info.processName;
adapter.add(icon + c.toString().toUpperCase() + "\n" + info.processName);
}
但它只返回一个字符串。如果可能,我希望图标不是字符串..是否可能?
答案 0 :(得分:0)
在listview适配器中使用此行来获取应用程序图标
PackageInfo packageInfo = (PackageInfo) getItem(position);
Drawable appIcon = packageManager.getApplicationIcon(packageInfo.applicationInfo);
String appName = packageManager.getApplicationLabel(
packageInfo.applicationInfo).toString();
appIcon.setBounds(0, 0, 40, 40);
holder.apkName.setCompoundDrawables(appIcon, null, null, null);
holder.apkName.setCompoundDrawablePadding(15);
holder.apkName.setText(appName);
请参阅以下网站以获取完整的源代码
http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/