Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get other applications icon uri?

I have an Android appwidget which shows icons of other applications on it.

I get the other applications icons with appInfo.loadIcon and then I set it to the widgets with setImageViewBitmap.

The problem is that if I have too many icons on the widget, I get "FAILED BINDER TRANSACTION" error. I understand that it's from a size limit and the solution it to use the image uri instead of the bitmap itself.

Is there an accessible URI to other applications' icons?

Thanks.

like image 217
Ran Avatar asked Nov 28 '22 18:11

Ran


1 Answers

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);
}
like image 68
Sven Avatar answered Nov 30 '22 08:11

Sven