首頁  >  文章  >  shortcut功能

shortcut功能

(*-*)浩
(*-*)浩原創
2019-12-21 10:31:574412瀏覽

shortcut功能

從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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn