66

I have tried various solution from stack overflow with no luck. What I want.

  1. I know package name of different applications.
  2. I want to get application Icon from those package name.
  3. Show those icons in Image View.

For example, I have a package name com.example.testnotification. How to get this apps icon and show it in an ImageView?

peterh
  • 1
  • 15
  • 76
  • 99

4 Answers4

148

Try this:

try
{
    Drawable icon = getContext().getPackageManager().getApplicationIcon("com.example.testnotification");
    imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}
ABHIMANGAL MS
  • 974
  • 12
  • 17
T_V
  • 17,308
  • 6
  • 34
  • 47
13

If you want to get the icon (picture) of any installed application from its package name, then just copy and paste this code. It will work:

try
{
    Drawable d = getPackageManager().getApplicationIcon("com.AdhamiPiranJhandukhel.com");
    my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
    return;
}
Bondolin
  • 2,536
  • 6
  • 30
  • 59
Pir Fahim Shah
  • 9,985
  • 1
  • 75
  • 78
9

This also works:

try
{
    Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
    my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
    return;
}
thecoolmacdude
  • 1,817
  • 22
  • 36
1
try
{
    Drawable drawable = getPackageManager()
            .getApplicationIcon("com.whatsapp");
    imageView.setImageDrawable(drawable);
}
catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}
pirho
  • 10,579
  • 12
  • 42
  • 61
saigopi.me
  • 11,721
  • 2
  • 72
  • 50