前言
最近更新了Android8.0,發(fā)現(xiàn)了有個新功能,就是桌面圖標上長安可以彈出菜單,如圖。點擊可進入相應的頁面。作為程序員你肯定想知道這是怎么做出來的吧,于是我就翻過去看了看。

正文
? ? ? ? ? ? 這個功能叫做APP?Shortcuts,有兩種注冊的方法,靜態(tài)注冊和動態(tài)注冊。
1.靜態(tài)注冊
在啟動界面的下添加 meta-data標簽

在xml文件下新建xml文件shortcut.xml

搞定
2.動態(tài)注冊
添加
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1") ? ? .setShortLabel("Web site") ? ? .setLongLabel("Open the web site") ? ? .setIcon(Icon.createWithResource(context, R.drawable.icon_website)) ? ? .setIntent(new Intent(Intent.ACTION_VIEW, ? ? ? ? ? ? ? ? ? ?Uri.parse("https://www.mysite.example.com/"))) ? ? .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
移除
shortcutManager.disableShortcuts(Arrays.asList("news","email","search","web"));???????
example:

結(jié)語
其實很簡單,還有其他的一些API請到谷歌開發(fā)者中心區(qū)查看吧,英語不好,看不太懂。
Github:https://github.com/jessing/LaucherBadgeDemo/tree/master