像这样试试
首先为PackageItem创建一个模型
public class PackageItem {
private Drawable icon;
private String name;
private String packageName;
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
}
第2步)
这将为您提供所有安装应用程序的列表以及应用程序名称、图标和包
public List<PackageItem> getInstalledApplication(){
PackageManager appInfo = getPackageManager();
List<ApplicationInfo> listInfo = appInfo.getInstalledApplications(0);
Collections.sort(listInfo, new ApplicationInfo.DisplayNameComparator(appInfo));
List<PackageItem> data = new ArrayList<PackageItem>();
for (int index = 0; index < listInfo.size(); index++) {
try {
ApplicationInfo content = listInfo.get(index);
if ((content.flags != ApplicationInfo.FLAG_SYSTEM) && content.enabled) {
if (content.icon != 0) {
PackageItem item = new PackageItem();
item.setName(getPackageManager().getApplicationLabel(content).toString());
item.setPackageName(content.packageName);
item.setIcon(getPackageManager().getDrawable(content.packageName, content.icon, content));
data.add(item);
}
}
} catch (Exception e) {
}
}
return data;
}
现在你可以在你的适配器类中使用这个List ,
希望这会帮助你。