0

I want adding at my listview the application icon from getPackageManager. i tryied something like:

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);
          }

but it returns only a string. I want the icon not the string if possible.. Is it possible?

David_D
  • 1,404
  • 4
  • 31
  • 65

1 Answers1

0

use this line in your listview adapter to get application icon

  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);

Refer below site for complete source code

http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/

Dinesh Raj
  • 664
  • 12
  • 30