【Android】實作類別似於QQ將好友的頭像用作捷徑。

來源:互聯網
上載者:User

標籤:

原因:寫這個的原因就是網上大都是告訴你如何用drawable裡的資源做捷徑,那麼本地的圖片能不能做捷徑呢?肯定是可以的,所以我找了下安卓的源碼,發現有這樣的介紹
    /**     * 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     */

不難看出有兩種方式建立捷徑表徵圖,不過大都用的第一種。所以我們就試試第二種吧。解決方案:既然都看了源碼的介紹了,自然就知道怎麼做了。
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, "測試");// Intent.EXTRA_SHORTCUT_ICON 是bitmap對象shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeFile("路徑"));context.sendBroadcast(shortcut);}


【Android】實作類別似於QQ將好友的頭像用作捷徑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.