Get other applications icon uri?

守給你的承諾、 提交于 2019-12-05 13:58:17

Try android.resource://[package]/[res type]/[res name], where [res type] in your case would be drawable. The package and name would have to come from the ResolveInfo or wherever you are getting your data.

In case you don't know the resource name, you can also access resources by their id:

android.resource://[package]/[res_id]

The resource id of the app icon is available in the ApplicationInfo of the app:

ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
if(appInfo.icon != 0) {
    Uri uri = Uri.parse("android.resource://" + packageName + "/" + appInfo.icon);
}
Zap

While @CommonWare's answer is good in many cases, I find that this is often easier: android.resource://[package]/[res id] - especially when you want a reference to for instance the launcher icon of some other app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!