[Android] is similar to QQ, which uses a friend's profile picture as a shortcut ., Android is similar

Source: Internet
Author: User

[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 );}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.