我正在开发一个应用程序,我希望在我的应用程序中运行应用程序图标,但我无法执行此操作。我想按顺序生成这些图标。
下面我有代码。
public void getAllICONS() {
List<Drawable> icons = null;
PackageManager pm = getPackageManager();
ActivityManager am1 = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> processes = am1
.getRunningTasks(Integer.MAX_VALUE);
if (processes != null) {
for (int k = 0; k < 5; k++) {
// String pkgName = app.getPackageName();
String packageName = processes.get(k).topActivity
.getPackageName();
Drawable ico = null;
try {
String pName = (String) pm.getApplicationLabel(pm
.getApplicationInfo(packageName,
PackageManager.GET_META_DATA));
appList.add("" + pName);
ApplicationInfo a = pm.getApplicationInfo(packageName,
PackageManager.GET_META_DATA);
ico = getPackageManager().getApplicationIcon(
processes.get(k).topActivity.getPackageName());
getPackageManager();
} catch (PackageManager.NameNotFoundException e) {
}
// icons.put(processes.get(k).topActivity.getPackageName(),ico);
icons.add(ico);
}
}
}
我在icons.add(ico)
行收到错误。
答案 0 :(得分:1)
您正在尝试将项目添加到空列表中:
List<Drawable> icons = null;
首先尝试实例化一个空列表:
List<Drawable> icons = new ArrayList<Drawable>();