如何运行应用程序图标?

时间:2016-07-14 16:19:01

标签: android android-icons

**我发现这个how to get running applications icon on android programmatically关于我们如何显示正在运行的应用程序的图标和名称但是idont知道icon.add(ico);和name.add(“”+ pName)的类型;是这样可以帮助我,我该怎么办才能让它运行**

public void getAllICONS() {

    PackageManager pm = getPackageManager();

    ActivityManager am1 = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    List<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();
            Log.e("packageName-->", "" + packageName);
            Drawable ico = null;
            try {
                String pName = (String) pm.getApplicationLabel(pm
                        .getApplicationInfo(packageName,
                                PackageManager.GET_META_DATA));
                name.add("" + pName);
                ApplicationInfo a = pm.getApplicationInfo(packageName,
                        PackageManager.GET_META_DATA);
                ico = getPackageManager().getApplicationIcon(
                        processes.get(k).topActivity.getPackageName());
                getPackageManager();
                Log.e("ico-->", "" + ico);

            } catch (NameNotFoundException e) {
                Log.e("ERROR", "Unable to find icon for package '"
                        + packageName + "': " + e.getMessage());
            }
            // icons.put(processes.get(k).topActivity.getPackageName(),ico);
            icons.add(ico);

        }
    }
}

0 个答案:

没有答案