set different icon/image for shortcut ?

给你一囗甜甜゛ 提交于 2019-12-13 04:46:14

问题


I have written a program that can create shortcut of my application in android emulator homescreen.But the problem is when i created the shortcut then it has the default android icon. My question is how can i change the icon of the shortcut ?

I have used the following line to set the icon

Intent j=new Intent();
j.putExtra(Intent.EXTRA_SHORTCUT_INTENT,i);     
j.putExtra(Intent.EXTRA_SHORTCUT_NAME,n);                                                   
j.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,R.drawable.icon);
j.putExtra ("duplicate", false);
j.setAction("com.android.launcher.action.INSTALL_SHORTCUT");   
sendBroadcast(j);

回答1:


The system is not in your context. You therefore need to give more details to send you icon.

see https://github.com/ldo/ShortcutCircus_Android/blob/master/src/Activity2.java

The icon is given by :

Intent.ShortcutIconResource.fromContext(Activity2.this, R.drawable.icon)

Or you could decode the bitmap and use EXTRA_SHORTCUT_ICON instead.




回答2:


You can do this in two way.

putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,resId);

putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);



来源:https://stackoverflow.com/questions/10124063/set-different-icon-image-for-shortcut

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