Creating a shortcut: how can I work with a drawable as Icon?

≯℡__Kan透↙ 提交于 2019-12-03 03:26:55
Waza_Be

Finally found a solution; I was stupid to use Intent.EXTRA_SHORTCUT_ICON_RESOURCE:

Here is the correct code:

Drawable iconDrawable = (....); 
BitmapDrawable bd = (BitmapDrawable) iconDrawable;
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());
Bartho

I can't comment since I have only 23 reputation, but I used your code and it was usefull. But my image didn't scaled correctly on the shortcut, so I found two interesting topics that can complete the solution:

To get the correct size for a shortcut icon: https://stackoverflow.com/a/19003905/3741926

To scale your drawable (using the size you calculated with the previous function) https://stackoverflow.com/a/10703256/3741926

With all that I got a shortcut with a correctly scaled icon, hope it will help

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