如何从包名中获取应用程序的图标?

时间:2021-11-22 21:48:13

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

我已经尝试了堆栈溢出的各种解决方案,没有运气。我想要的是。

  1. I know package name of different applications.
  2. 我知道不同应用程序的包名称。
  3. I want to get application Icon from those package name.
  4. 我想从这些包名中获取应用程序图标。
  5. Show those icons in Image View.
  6. 在图像视图中显示这些图标。

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

例如,我有一个包名com.example.testnotification。如何获取此应用程序图标并在ImageView中显示它?

4 个解决方案

#1


98  

Try this-

尝试这个-

    try {

    Drawable icon = getPackageManager().getApplicationIcon("com.example.testnotification");
    imageView.setImageDrawable(icon);

       } 
 catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

#2


8  

if you want to get icon (picture) of any installed application from there packagename, then just copy and paste this code. it will work

如果你想从packagename获取任何已安装应用程序的图标(图片),那么只需复制并粘贴此代码即可。它会工作

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

#3


6  

This also works:

这也有效:

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

#4


1  

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

#1


98  

Try this-

尝试这个-

    try {

    Drawable icon = getPackageManager().getApplicationIcon("com.example.testnotification");
    imageView.setImageDrawable(icon);

       } 
 catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

#2


8  

if you want to get icon (picture) of any installed application from there packagename, then just copy and paste this code. it will work

如果你想从packagename获取任何已安装应用程序的图标(图片),那么只需复制并粘贴此代码即可。它会工作

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

#3


6  

This also works:

这也有效:

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

#4


1  

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