我已尝试过堆栈溢出的各种解决方案而没有运气。我想要的是什么。
例如,我有一个包名com.example.testnotification
。如何获取此应用程序图标并在ImageView中显示它?
答案 0 :(得分:115)
试试这个:
try
{
Drawable icon = getPackageManager().getApplicationIcon("com.example.testnotification");
imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
答案 1 :(得分:9)
如果您想从packagename获取任何已安装应用程序的图标(图片),则只需复制并粘贴此代码即可。它会起作用
try
{
Drawable d = getPackageManager().getApplicationIcon("com.AdhamiPiranJhandukhel.com");
my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
return;
}
答案 2 :(得分:7)
这也有效:
try
{
Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
my_imageView.setBackgroundDrawable(d);
}
catch (PackageManager.NameNotFoundException e)
{
return;
}
答案 3 :(得分:1)
try
{
Drawable drawable = getPackageManager()
.getApplicationIcon("com.whatsapp");
imageView.setImageDrawable(drawable);
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}