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

后端 未结 4 1705
忘了有多久
忘了有多久 2020-12-01 03:26

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
相关标签:
4条回答
  • 2020-12-01 03:48

    if you want to get icon (picture) of any installed application from there packagename, 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;
    }
    
    0 讨论(0)
  • 2020-12-01 03:56

    Try this:

    try
    {
        Drawable icon = getContext().getPackageManager().getApplicationIcon("com.example.testnotification");
        imageView.setImageDrawable(icon);
    }
    catch (PackageManager.NameNotFoundException e)
    {
        e.printStackTrace();
    }
    
    0 讨论(0)
  • 2020-12-01 04:06

    This also works:

    try
    {
        Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
        my_imageView.setBackgroundDrawable(d);
    }
    catch (PackageManager.NameNotFoundException e)
    {
        return;
    }
    
    0 讨论(0)
  • 2020-12-01 04:06
    try
    {
        Drawable drawable = getPackageManager()
                .getApplicationIcon("com.whatsapp");
        imageView.setImageDrawable(drawable);
    }
    catch (PackageManager.NameNotFoundException e)
    {
        e.printStackTrace();
    }
    
    0 讨论(0)
提交回复
热议问题