捷徑的最佳做法
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
設計及建立應用程式捷徑時,請遵循下列規範:
-
遵循設計規範
-
為了讓應用程式捷徑與系統應用程式使用的捷徑看起來一致,請遵守「應用程式捷徑圖示設計指南」。
-
僅發布四個不同的捷徑
-
雖然這個 API 最多支援應用程式 15 個靜態和動態捷徑,但建議您只發布四個不同的捷徑,以改善捷徑在啟動器中的視覺外觀。
除了在啟動器中顯示捷徑以外,您也可以使用 Google 捷徑整合程式庫在 Google 介面 (例如 Google 助理) 上顯示捷徑。這個程式庫支援推送不限數量的動態捷徑。如果您使用這個程式庫推送大量捷徑,建議您呼叫 setRank()
方法,設定必須在支援的啟動器中顯示的捷徑 rank
。
-
限制捷徑說明長度
-
選單中顯示應用程式捷徑的選單空間有限。請盡可能將捷徑的「簡短說明」長度限制在 10 個半形字元以內,並將「詳細說明」的長度限制在 25 個半形字元以內。
如要進一步瞭解靜態捷徑的標籤,請參閱「自訂屬性值」。針對動態和固定捷徑,請參閱 setLongLabel()
和 setShortLabel()
的參考說明文件。
-
保留捷徑和動作使用記錄
-
針對您建立的每個捷徑,思考使用者可透過哪些不同方式直接在應用程式內完成相同工作。在這些情況下呼叫 reportShortcutUsed()
,讓啟動器準確記錄使用者執行代表捷徑動作的頻率。
-
只在捷徑保有自身涵義時更新捷徑
-
變更動態和固定捷徑時,只有在變更能保留其意義的捷徑資訊時,才需要呼叫 updateShortcuts()
。否則,請根據您要重新建立的捷徑類型,使用以下其中一種方法:
舉例來說,如果您建立前往超市的捷徑,如果超市的名稱有所變更,但位置維持不變,更新捷徑就適合您。不過,如果使用者開始在其他超市地點購物,建議您建立新的捷徑。
-
每次啟動應用程式時檢查動態捷徑
-
使用者將資料還原至新裝置時,系統不會保留動態捷徑。因此,建議您每次啟動應用程式時檢查 getDynamicShortcuts()
傳回的物件數量,並視需要重新發布動態捷徑,如備份與還原的程式碼片段所示。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Best practices for shortcuts\n\nWhen designing and creating your app's shortcuts, follow these guidelines:\n\n\n**Follow the design guidelines**\n\n: To make your app's shortcuts visually consistent with the shortcuts used for system apps, follow\n the\n [App Shortcuts Icon Design Guidelines](/static/shareables/design/app-shortcuts-design-guidelines.pdf).\n\n\n**Publish only four distinct shortcuts**\n\n: Although the API supports a combination of up to 15 static and dynamic shortcuts for your app, we\n recommend that you publish only four distinct shortcuts, to improve their visual appearance in the\n launcher.\n\n In addition to displaying shortcuts on the launcher, use the\n [Google Shortcuts Integration Library](/develop/ui/views/launch/shortcuts/creating-shortcuts#gsi-library)\n to display shortcuts on Google surfaces such as Google Assistant. This library supports pushing an\n unlimited number of dynamic shortcuts. If you are using this library to push a large number of\n shortcuts, we recommend setting the `rank` of the shortcuts that must appear in supported\n launchers by calling the\n [](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setRank(int))`setRank()`\n method.\n\n\n**Limit shortcut description length**\n\n: The space in the menu that shows your app's shortcuts in the launcher is limited. When possible,\n limit the length of the \"short description\" of a shortcut to 10 characters and limit the length of\n the \"long description\" to 25 characters.\n\n For more information about labels for static shortcuts, read\n [Customize attribute values](/guide/topics/ui/shortcuts/creating-shortcuts#attribute-values).\n For dynamic and pinned shortcuts, read the reference documentation on\n [setLongLabel()](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLongLabel(java.lang.CharSequence))\n and\n [setShortLabel()](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setShortLabel(java.lang.CharSequence)).\n\n\n**Maintain shortcut and action usage history**\n\n: For each shortcut you create, consider the different ways a user can accomplish the same task\n directly within your app. Call\n [reportShortcutUsed()](/reference/androidx/core/content/pm/ShortcutManagerCompat#reportShortcutUsed(android.content.Context,%20java.lang.String))\n in each of these situations so that the launcher maintains an accurate history of how frequently a\n user performs the actions representing your shortcuts.\n\n\n**Update shortcuts only when their meaning is retained**\n\n: When changing dynamic and pinned shortcuts, only call\n [updateShortcuts()](/reference/androidx/core/content/pm/ShortcutManagerCompat#updateShortcuts(android.content.Context,%20java.util.List%3Candroidx.core.content.pm.ShortcutInfoCompat%3E))\n when changing the information of a shortcut that retains its meaning. Otherwise, use one of the\n following methods, depending on the type of shortcut you're recreating:\n\n - Dynamic shortcuts: [pushDynamicShortcut()](/reference/androidx/core/content/pm/ShortcutManagerCompat#pushDynamicShortcut(android.content.Context,%20androidx.core.content.pm.ShortcutInfoCompat)).\n - Pinned shortcuts: [requestPinShortcut()](/reference/androidx/core/content/pm/ShortcutManagerCompat#requestPinShortcut(android.content.Context,%20androidx.core.content.pm.ShortcutInfoCompat,%20android.content.IntentSender)).\n\n For example, if you create a shortcut for navigating to a supermarket, it is appropriate to\n update the shortcut if the name of the supermarket changes but its location stays the same. If the\n user begins shopping at a different supermarket location, however, it's better to create a new\n shortcut.\n\n\n**Check dynamic shortcuts whenever you launch your app**\n\n: Dynamic shortcuts aren't preserved when the user restores their data onto a new device. For this\n reason, we recommend that you check the number of objects returned by\n [getDynamicShortcuts()](/reference/androidx/core/content/pm/ShortcutManagerCompat#getDynamicShortcuts(android.content.Context))\n each time you launch your app and re-publish dynamic shortcuts as needed, as shown in the code\n snippet in\n [Backup and restore](/guide/topics/ui/shortcuts/managing-shortcuts#backup-restore)."]]