快捷方式最佳实践
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在设计和创建应用快捷方式时,请遵循以下准则:
-
遵循设计准则
-
为了使应用的快捷方式在视觉上与系统应用使用的快捷方式保持一致,请遵循应用快捷方式图标设计准则。
-
仅发布四个不同的快捷方式
-
尽管该 API 可为您的应用组合使用最多 15 个静态和动态快捷方式,但我们建议您仅发布 4 个不同的快捷方式,以改善其在启动器中的视觉外观。
除了在启动器上显示快捷方式之外,您还可以使用 Google 快捷方式集成库在 Google Surface(例如 Google 助理)上显示快捷方式。此库支持推送任意数量的动态快捷方式。如果您使用此库推送大量快捷方式,我们建议您通过调用 setRank()
方法来设置必须出现在受支持的启动器中的快捷方式的 rank
。
-
限制快捷方式说明的长度
-
在启动器中显示应用快捷方式的菜单中是有限的。请尽可能将快捷方式的“简短说明”的长度限制在 10 个字符以内,并将“详细说明”的长度限制在 25 个字符以内。
如需详细了解静态快捷方式的标签,请参阅自定义属性值。
如需了解动态和固定快捷方式,请参阅有关 setLongLabel()
和 setShortLabel()
的参考文档。
-
保留快捷方式和操作的使用记录
-
对于您创建的每个快捷方式,请考虑用户可以采用哪些不同方式直接在您的应用中完成同一任务。在每种情况下调用 reportShortcutUsed()
,以便启动器准确记录用户执行代表快捷方式的操作的频率。
-
仅对含义未变的快捷方式执行更新
-
更改动态和固定快捷方式时,只有在更改的信息保持不变时,才能调用 updateShortcuts()
。否则,请使用以下方法之一,具体取决于您要重新创建的快捷方式的类型:
例如,如果您创建了用于导航到超市的快捷方式,则当超市的名称发生变化但其位置保持不变时,最好更新快捷方式。但是,如果用户开始在其他超市购物,则最好创建新的快捷方式。
-
发布应用时即检查动态快捷方式
-
当用户将数据恢复到新设备上时,系统不会保留动态快捷方式。因此,我们建议您在每次启动应用时检查 getDynamicShortcuts()
返回的对象数量,并根据需要重新发布动态快捷方式,如备份和恢复中的代码段所示。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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)."]]