Reason: The reason for writing this is that the Internet is mostly to tell you how to use the resources in the drawable to do shortcuts, then the local image can do shortcut it? Must be able, so I looked for the next Android source, found that there is such an introduction
/** * Activity action:creates a shortcut. * <p>Input:Nothing.</p> * <p>output:an Intent representing the shortcut. The intent must contain three * Extras:shortcut_intent (value:intent), Shortcut_name (value:string), * and SHOR Tcut_icon (Value:bitmap) or Shortcut_icon_resource * (value:shortcuticonresource) .</p> * * @see # Extra_shortcut_intent * @see #EXTRA_SHORTCUT_NAME * @see #EXTRA_SHORTCUT_ICON * @see #EXTRA_SHORTCUT_ Icon_resource * @see Android.content.Intent.ShortcutIconResource * *
It's not hard to see that there are two ways to create a shortcut icon, but most of the first. So let's try the second kind. Solution: Since all read the introduction of the source code, Nature will know how to do it.
public void Createshotcast (context context, class<?> Clazz) {Intent shortcut = new Intent (intent.action_create_ SHORTCUT); Intent shortcutintent = new Intent (intent.action_main); Shortcutintent.setclass (context, clazz); Shortcut.putextra (Intent.extra_shortcut_intent, shortcutintent); Shortcut.putextra (Intent.EXTRA_SHORTCUT_NAME, " Test "),//Intent.extra_shortcut_icon is the Bitmap object Shortcut.putextra (Intent.extra_shortcut_icon, Bitmapfactory.decodefile ("path")); context.sendbroadcast (shortcut);}
The "Android" implementation is similar to QQ using a friend's avatar as a shortcut.