標籤:
原因:寫這個的原因就是網上大都是告訴你如何用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將好友的頭像用作捷徑。