標籤:android style blog class code c
如下58同城捷徑的效果:
下面是添加案頭捷徑:
/** * 啟動某個activity是需要在manifest裡面定義 <intent-filter> <action * android:name="android.intent.action.MAIN" /> </intent-filter> */private void addShortCut(){// 安裝的IntentIntent shortcut =new Intent("com.android.launcher.action.INSTALL_SHORTCUT");// 快捷名稱shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "家居");// 快捷表徵圖是允許重複shortcut.putExtra("duplicate", false);Intent shortcutIntent = new Intent();shortcutIntent.putExtra("tName", "家居");// shortcutIntent.setClass(mContext, HouseJjActivity.class);shortcutIntent.setClassName("com.shangc.houseproperty","com.shangc.houseproperty.ui.activity.TestActivity");shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);// 快捷表徵圖ShortcutIconResource iconRes =Intent.ShortcutIconResource.fromContext(mContext,R.drawable.ic_launcher);shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);// 發送廣播mContext.sendBroadcast(shortcut);}
通過表徵圖啟動一個半透明的activity,在這個activity管理小工具什麼的。上面注釋標紅的很重要....剛開始弄了好久都不行,提示應用未安裝什麼的錯誤。
當然記得加許可權:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
半透明的activity很簡單了.....