[Android] is similar to QQ, which uses a friend's profile picture as a shortcut ., Android is similar
Cause: the reason for writing this is that most people on the internet tell you how to use resources in drawable for shortcuts, so can local images be used for shortcuts? Yes, so I found the android source code and found this 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 SHORTCUT_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 is not hard to see that there are two ways to create shortcuts, but most of them are the first. So let's try the second one. Solution: Since I have read the source code introduction, I naturally 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 );}