android捷徑shortcut 管理

來源:互聯網
上載者:User

標籤: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很簡單了.....

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.