قابلیت ها را به میانبرها اضافه کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
قابلیتهای shortcuts.xml
به شما امکان میدهد انواع اقداماتی را که کاربران میتوانند برای راهاندازی برنامهتان انجام دهند و مستقیماً یک کار خاص انجام دهند، اعلام کنید.
برای مثال، Google Assistant App Actions از قابلیتهایی استفاده میکند که به توسعهدهندگان اجازه میدهد ویژگیهای درونبرنامه را به مقاصد داخلی (BII) گسترش دهند و به کاربران این امکان را میدهد تا با استفاده از دستورات گفتاری آن ویژگیها را فعال و کنترل کنند. یک قابلیت شامل نام عمل و intent
است که مقصد را در برنامه شما هدف قرار می دهد که هدف کاربر را برطرف می کند.
قابلیت ها را در shortcuts.xml تعریف کنید
شما عناصر capability
در یک فایل منبع shortcuts.xml
در پروژه توسعه برنامه Android خود تعریف می کنید. برای تعریف عنصر capability
، موارد زیر را انجام دهید:
- با دنبال کردن دستورالعملهای موجود در Create static shortcuts، یک منبع
shortcuts.xml
ایجاد کنید. اطلاعات مورد نیاز زیر را در توانایی خود بگنجانید:
نام قابلیت: اقدامی که میخواهید برنامه شما از آن پشتیبانی کند. برای ویژگی هایی که به تعریف قابلیت نیاز دارند به مستندات مؤلفه مراجعه کنید. فرمانهای فعالسازی صوتی App Actions Action ID
BII برای نامهای قابلیتها استفاده میکنند که میتوانید در مرجع BII پیدا کنید. برای مثال، GET_THING
BII Action ID
خود را بهعنوان actions.intent.GET_THING
فهرست میکند.
مقصد برنامه: مقصدی که در برنامه شما انجام میشود تا درخواست کاربر را برآورده کند. با استفاده از عناصر intent
تو در تو در داخل capability
مقصد برنامه را تعریف کنید.
نگاشت پارامترها: هر intent
ممکن است حاوی پارامترهایی باشد که به عنوان داده های extra
قصد ارسال شوند. برای مثال، هر App Actions BII شامل فیلدهایی است که نشان دهنده اطلاعاتی است که کاربران اغلب در جستارهایی که BII را راهاندازی میکنند ارائه میکنند.
مثال زیر یک تعریف قابلیت را در shortcuts.xml
برای actions.intent.START_EXERCISE
نشان میدهد، یک BII که به کاربران اجازه میدهد از دستورات گفتاری با Assistant برای شروع تمرین در یک برنامه تناسب اندام استفاده کنند:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.START_EXERCISE">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.sampleApp"
android:targetClass="com.example.sampleApp.ExerciseActivity">
<parameter
android:name="exercise.name"
android:key="exerciseType"/>
</intent>
</capability>
</shortcuts>
در مثال قبل، ویژگی <capability>
android:name
به START_EXERCISE
BII اشاره دارد. اگر کاربری این BII را با پرسیدن «Hey Google, start a run in ExampleApp» از «دستیار» فراخوانی کند، «دستیار» درخواست کاربر را با استفاده از اطلاعات ارائه شده در عنصر intent
تودرتو برآورده میکند. intent
در این نمونه جزئیات زیر را تعریف می کند:
-
android:targetPackage
بسته برنامه هدف را برای این هدف تنظیم می کند. - فیلد
android:targetClass
فعالیت مقصد را مشخص میکند: com.example.sampleApp.ExerciseActivity
. -
parameter
intent پشتیبانی از یک پارامتر BII exercise.name
و نحوه ارسال مقدار پارامتر - جمع آوری شده از کاربر - را به عنوان داده اضافی در intent
اعلام می کند.
میانبرها را با یک قابلیت مرتبط کنید
هنگامی که یک قابلیت را تعریف کردید، می توانید عملکرد آن را با مرتبط کردن میانبرهای ایستا یا پویا با آن گسترش دهید. نحوه پیوند میانبرها به یک capability
بستگی به ویژگی در حال پیاده سازی و کلمات واقعی موجود در درخواست کاربر دارد. به عنوان مثال، زمانی که کاربری با پرسیدن «Hey Google, start a run in ExampleApp» را از «دستیار» شروع به اجرای برنامه ردیابی تناسب اندام شما می کند. Assistant میتواند از یک میانبر برای راهاندازی نمونهای از capability
استفاده کند که یک موجودیت تمرین معتبر "run" را برای پارامتر exercise.name
تعریف میکند.
برای اطلاعات بیشتر در مورد مرتبط کردن میانبرها به عملکردهای برنامه، به نمای کلی اقدامات برنامه مراجعه کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-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-08-27 بهوقت ساعت هماهنگ جهانی."],[],[],null,["Capabilities in `shortcuts.xml` let you declare the types of actions users can\ntake to launch your app and directly perform a specific task.\n\nFor example, Google Assistant App Actions use capabilities to let developers\nextend in-app features to [built-in intents](//developers.google.com/assistant/app/intents) (BIIs), letting users activate\nand control those features using spoken commands. A capability consists of the\nname of the action and an `intent` targeting the destination in your app that\nresolves the user intent.\n\nDefine capabilities in shortcuts.xml\n\nYou define `capability` elements in a `shortcuts.xml` resource file in your\nAndroid app development project. To define a `capability` element, do the\nfollowing:\n\n1. Create a `shortcuts.xml` resource by following the instructions in [Create\n static shortcuts](//develop/ui/views/launch/shortcuts/creating-shortcuts#static).\n2. Include the following required information in your capability:\n\n - **Capability name:** the action you want your app to support. Refer to\n the component documentation for the feature that requires capability\n definitions. App Actions voice-enabled commands use the BII `Action ID`\n for capability names, which you can find in [BII reference](//developers.google.com/assistant/app/reference/built-in-intents). For example,\n the [`GET_THING`](//developers.google.com/assistant/app/reference/built-in-intents/common/get-thing) BII lists its `Action ID` as `actions.intent.GET_THING`.\n\n - **App destination:** the destination in your app the action launches to\n fulfill the user request. Define app destinations using `intent` elements\n nested within the `capability`.\n\n - **Parameter mappings:** each `intent` might contain parameters to be\n passed as `extra` data of the intent. For example, each App Actions BII\n includes fields representing information users often provide in queries that\n trigger the BII.\n\nThe following example demonstrates a capability definition in `shortcuts.xml`\nfor [`actions.intent.START_EXERCISE`](//developers.google.com/assistant/app/reference/built-in-intents/health-and-fitness/start-exercise), a BII that lets users use spoken\ncommands with Assistant to begin a workout in a fitness app: \n\n \u003cshortcuts xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n \u003ccapability android:name=\"actions.intent.START_EXERCISE\"\u003e\n \u003cintent\n android:action=\"android.intent.action.VIEW\"\n android:targetPackage=\"com.example.sampleApp\"\n android:targetClass=\"com.example.sampleApp.ExerciseActivity\"\u003e\n \u003cparameter\n android:name=\"exercise.name\"\n android:key=\"exerciseType\"/\u003e\n \u003c/intent\u003e\n \u003c/capability\u003e\n \u003c/shortcuts\u003e\n\nIn the preceding example, the `\u003ccapability\u003e` `android:name` attribute refers to\nthe `START_EXERCISE` BII. If a user invokes this BII by asking Assistant, *\"Hey\nGoogle, start a run in ExampleApp,\"* Assistant fulfills the user request using\ninformation provided in the nested `intent` element. The `intent` in this sample\ndefines the following details:\n\n- The `android:targetPackage` sets the target application package for this intent.\n- The `android:targetClass` field specifies the destination activity: `com.example.sampleApp.ExerciseActivity`.\n- The intent `parameter` declares support for a BII parameter [`exercise.name`](//developers.google.com/assistant/app/reference/built-in-intents/health-and-fitness/start-exercise#recommended-fields) and how to pass the parameter value---collected from the user---as extra data in the `intent`.\n\nAssociate shortcuts with a capability\n\nOnce you define a capability, you can extend its functionality by associating\nstatic or dynamic shortcuts with it. How shortcuts are linked to a `capability`\ndepends on the feature being implemented and the actual words included in a\nuser's request. For example, when a user begins a run in your fitness tracking\napp by asking Assistant, *\"Hey Google, start a run in ExampleApp.\"* Assistant\ncan use a shortcut to launch an instance of a `capability` that defines a valid\nexercise entity of \"run\" for the `exercise.name` parameter.\n\nFor more information about associating shortcuts to App Actions, see [App\nActions overview](//developers.google.com/assistant/app)."]]