แนวทางปฏิบัติที่ดีที่สุดสำหรับทางลัด
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อออกแบบและสร้างทางลัดของแอป ให้ทำตามหลักเกณฑ์ต่อไปนี้
-
ปฏิบัติตามหลักเกณฑ์การออกแบบ
-
หากต้องการให้ทางลัดของแอปมีความสอดคล้องกับทางลัดที่ใช้สำหรับแอปของระบบ ให้ทำตามหลักเกณฑ์การออกแบบไอคอนทางลัดของแอป
-
เผยแพร่แป้นพิมพ์ลัดที่แตกต่างกันเพียง 4 รายการ
-
แม้ว่า API จะรองรับการผสมผสานทางลัดแบบคงที่และแบบไดนามิกได้สูงสุด 15 รายการสำหรับแอปของคุณ แต่เราขอแนะนำให้เผยแพร่ทางลัดที่แตกต่างกันเพียง 4 รายการเพื่อปรับปรุงลักษณะที่ปรากฏใน Launcher
นอกเหนือจากการแสดงทางลัดใน Launcher แล้ว ให้ใช้
ไลบรารีการผสานรวมทางลัดของ Google
เพื่อแสดงทางลัดในแพลตฟอร์มของ Google เช่น Google Assistant ไลบรารีนี้รองรับการพุชทางลัดแบบไดนามิกจำนวนไม่จำกัด
หากคุณใช้ไลบรารีนี้เพื่อพุชทางลัดจำนวนมาก เราขอแนะนำให้ตั้งค่า rank
ของทางลัดที่ต้องปรากฏในตัวเรียกใช้ที่รองรับโดยการเรียกใช้เมธอด setRank()
-
จำกัดความยาวของคำอธิบายทางลัด
-
พื้นที่ในเมนูที่แสดงทางลัดของแอปใน Launcher มีจำกัด หากเป็นไปได้ ให้จำกัดความยาวของ "คำอธิบายแบบย่อ" ของทางลัดไว้ที่ 10 อักขระ และจำกัดความยาวของ "คำอธิบายแบบยาว" ไว้ที่ 25 อักขระ
ดูข้อมูลเพิ่มเติมเกี่ยวกับป้ายกำกับสำหรับทางลัดแบบคงที่ได้ที่ปรับแต่งค่าแอตทริบิวต์
สำหรับทางลัดแบบไดนามิกและทางลัดที่ปักหมุด โปรดอ่านเอกสารอ้างอิงที่
setLongLabel()
และ
setShortLabel()
-
เก็บประวัติการใช้งานทางลัดและการดำเนินการ
-
สำหรับทางลัดแต่ละรายการที่คุณสร้าง ให้พิจารณาวิธีต่างๆ ที่ผู้ใช้สามารถทํางานเดียวกันให้เสร็จสมบูรณ์ได้
โดยตรงภายในแอปของคุณ เรียกใช้
reportShortcutUsed()
ในแต่ละสถานการณ์เหล่านี้เพื่อให้ Launcher รักษาประวัติที่ถูกต้องเกี่ยวกับความถี่ที่ผู้ใช้
ดําเนินการที่แสดงถึงทางลัดของคุณ
-
อัปเดตทางลัดเฉพาะเมื่อยังคงความหมายเดิมไว้
-
เมื่อเปลี่ยนทางลัดแบบไดนามิกและทางลัดที่ปักหมุด ให้เรียกใช้
updateShortcuts()
เมื่อเปลี่ยนข้อมูลของทางลัดที่ยังคงความหมายเดิม หรือใช้วิธีใดวิธีหนึ่งต่อไปนี้ ขึ้นอยู่กับประเภทของทางลัดที่คุณสร้างใหม่
ตัวอย่างเช่น หากคุณสร้างทางลัดสำหรับการไปยังซูเปอร์มาร์เก็ต คุณควร
อัปเดตทางลัดหากชื่อของซูเปอร์มาร์เก็ตเปลี่ยนไป แต่ตำแหน่งยังคงเดิม อย่างไรก็ตาม หากผู้ใช้เริ่มช็อปปิ้งที่ซูเปอร์มาร์เก็ตสาขาอื่น คุณควรสร้างทางลัดใหม่
-
ตรวจสอบทางลัดแบบไดนามิกทุกครั้งที่เปิดแอป
-
ระบบจะไม่เก็บทางลัดแบบไดนามิกไว้เมื่อผู้ใช้กู้คืนข้อมูลไปยังอุปกรณ์ใหม่ ด้วยเหตุนี้ เราจึงขอแนะนำให้คุณตรวจสอบจำนวนออบเจ็กต์ที่ส่งคืนโดยgetDynamicShortcuts()
ทุกครั้งที่คุณเปิดแอป และเผยแพร่ทางลัดแบบไดนามิกอีกครั้งตามที่จำเป็น ดังที่แสดงในโค้ด
ข้อมูลโค้ดในสำรองและกู้คืน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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)."]]