How can I get the application's icon from the package name?
Solution 1:
Try this:
try
{
Drawable icon = getContext().getPackageManager().getApplicationIcon("com.example.testnotification");
imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
Solution 2:
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;
}
Solution 3:
This also works:
try
{
Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
return;
}
Solution 4:
try
{
Drawable drawable = getPackageManager()
.getApplicationIcon("com.whatsapp");
imageView.setImageDrawable(drawable);
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}