從Android N開始GoogleLauncher提供了shortcut功能,方便用戶能更快的使用應用程式提供的功能服務(例如下圖),當你每次支付的時候都要打開應用,找到支付的按鈕,是不是這種方式比較便捷。
這裡就要詳細說說第三方應用如何新增和管理自己的shortcut。 (建議學習:phpstorm)
Android對shortcut是有權限要求的,不是所有的Launcher都能展示應用的shortcut,來源碼裡對權限是這麼原始碼說明的
Only the default launcher can access the shortcut information.
只有被設定為預設Launcher的桌面才有取得shortcut的權限。如何讓非預設桌面也取得shortcut權限呢 也是有辦法的,後面再研究。
靜態shortcut
Android支援靜態shutcut和動態shortcut,對於動態的shortcut不需要在manifest裡做任何的配置,對於靜態的只需要聲明一下meta -data即可
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
動態的shortcut
framework提供了ShortcutManager來管理shortcut, 取得ShortcutManager的方法如下
mShortcutManager = mContext.getSystemService(ShortcutManager.class);
shortcut的更新
如果使用者切換語言,shortcut該如何更新?也許你早就猜到了,ShortcutManager肯定提供了更新的介面,需要重新取得一遍資源並set遍,最後調用下面的介面更新就好了。
public boolean updateShortcuts(List<ShortcutInfo> shortcutInfoList) { ... }
shortcut功能為應用程式提供了快速的入口,應用不但可以設定靜態的shortcut,也可以設定動態的,也可以使能或禁止shortcut,還可以根據使用者的使用行為,為不同的使用者提供不同的shortcut。
shortcut功能需要android系統sdk要在25以上,可惜的是國內的手機廠商更新較慢,還沒有大量普及,不過我相信這兩年就會有大量的應用提供這個功能
以上是shortcut功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能