Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the application's icon from the package name?

Tags:

android

People also ask

How do I get an app icon installed?

This the most common and easiest method to add directly accessible app shortcuts on your Android homescreen. Follow these easy steps to achieve the same. Open your App Drawer and locate your favorite app to create its shortcut. Long press the app icon and drag it to a free space on your homescreen.

What is the icon of application?

What is an app icon? An app icon is a unique image used to represent an app on a user's device. It also appears in Settings and Search and will first be seen by users on the App Store and Google Play store. Because users will see your app icon in various places, your icon's design must serve multiple purposes.

What is application Launcher icon?

A Launcher icon is a graphic that represents your application on the device's Home screen and in the Launcher window. The user opens the Launcher by touching the icon at the bottom of the Home screen. The Launcher opens and exposes the icons for all of the installed applications.


Try this:

try
{
    Drawable icon = getContext().getPackageManager().getApplicationIcon("com.example.testnotification");
    imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}

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

This also works:

try
{
    Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
    my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
    return;
}

try
{
    Drawable drawable = getPackageManager()
            .getApplicationIcon("com.whatsapp");
    imageView.setImageDrawable(drawable);
}
catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}