我想检索应用程序的图标。如果我使用获取应用程序图标作为int标识符
String pkg = "com.app.my";
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
结果是可绘制的。我如何检索相关资源的id,以便将其作为额外的意图传递给它?谢谢!
我想检索应用程序的图标。如果我使用获取应用程序图标作为int标识符
String pkg = "com.app.my";
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
结果是可绘制的。我如何检索相关资源的id,以便将其作为额外的意图传递给它?谢谢!
下面的代码片段应该做的伎俩。
PackageManager pm = getPackageManager();
String pkg = "com.app.my";
try {
ApplicationInfo ai = pm.getApplicationInfo(pkg, 0);
int iconId = ai.icon;
} catch (NameNotFoundException e) {
// ...
}
使用
getResources().getIdentifier() from your Context (e.g., Activity)
s=name of the drawable
int id=getResources().getIdentifier(s,"drawable",getPackageName());
you will get the id here
谢谢,但我不知道可绘制的名称:P – Addev 2011-12-17 19:10:47
您是指其他应用程序的图标或您所在的应用程序?
如果它在应用程序中,那么这应该足够了吗?
int i = R.drawable.icon;
谢谢,但我不知道可绘制的名称:P – Addev 2011-12-17 19:10:40