获取应用程序图标为int标识符 [英] Get the app icon as int identifier

查看:170
本文介绍了获取应用程序图标为int标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索应用程序的图标。如果我用

I want to retrieve the icon of an app. If I use

String pkg = "com.app.my";
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);

其结果是一个可绘制。我怎么可以检索相关资源的ID为把它当作额外的在意图是什么?谢谢!

The result is a Drawable. how can I retrieve the id of the associated resource for passing it as extra in an intent? THanks!

推荐答案

下面的代码片段应该做的伎俩。

The following snippet should do the trick.

PackageManager pm = getPackageManager();
String pkg = "com.app.my";

try {
    ApplicationInfo ai = pm.getApplicationInfo(pkg, 0);
    int iconId = ai.icon;
} catch (NameNotFoundException e) {
    // ...
}

这篇关于获取应用程序图标为int标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆