ショートカットに機能を追加する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
shortcuts.xml
にケーパビリティを追加することで、アプリを起動して特定タスクを直接実行するためにユーザーがとれるアクションを宣言できます。
たとえば、Google アシスタント App Actions は、ケーパビリティを使用してデベロッパーがアプリ内機能を組み込みインテント(BII)に拡張できるようにし、これらの機能をユーザーが音声コマンドで起動、操作できるようにします。ケーパビリティは、アクションの名前と、ユーザー インテントを解決するアプリ内デスティネーションをターゲットとする intent
で構成されます。
shortcuts.xml にケーパビリティを定義する
Android アプリ開発プロジェクトの shortcuts.xml
リソース ファイルに capability
要素を定義します。capability
要素を定義する手順は以下のとおりです。
- 静的ショートカットを作成するの手順に沿って、
shortcuts.xml
リソースを作成します。
以下の必須情報をケーパビリティ定義に含めます。
ケーパビリティ名: アプリでサポートするアクション。ケーパビリティを定義する必要がある機能については、コンポーネントのドキュメントをご覧ください。App Actions 音声対応コマンドは、ケーパビリティ名に BII Action ID
を使用します。詳しくは、BII リファレンスをご覧ください。たとえば、GET_THING
BII の Action ID
は actions.intent.GET_THING
です。
アプリ デスティネーション: アプリ内でユーザーのリクエストに応えるアクションが開始されるデスティネーション。capability
内にネストされた intent
要素を使用してアプリ デスティネーションを定義します。
パラメータ マッピング: 各 intent
には、インテントの extra
データとして渡されるパラメータが含まれる場合があります。たとえば、各 App Actions BII には、BII をトリガーするクエリでユーザーがよく使う情報を表すフィールドが含まれています。
次の例は、shortcuts.xml
内での actions.intent.START_EXERCISE
(アシスタントを使った音声コマンドでフィットネス アプリのワークアウトを開始できるようにする BII)に対するケーパビリティ定義を示しています。
<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 を参照しています。ユーザーがアシスタントに「OK Google, ExampleApp でランニングを開始」と話しかけると、アシスタントは intent
要素にネストされた定義情報を使ってユーザーのリクエストに応えます。この例の intent
では、次の情報を定義しています。
android:targetPackage
に、このインテントのターゲット アプリケーション パッケージを設定しています。
android:targetClass
に、デスティネーション アクティビティ(com.example.sampleApp.ExerciseActivity
)を設定しています。
- インテントの
parameter
に、BII パラメータ exercise.name
のサポートと、ユーザーから収集されたパラメータ値を intent
の extra データとして渡す方法を宣言しています。
ショートカットとケーパビリティを関連付ける
ケーパビリティを定義した後は、静的ショートカットや動的ショートカットと関連付けることで、その機能を拡張できます。ショートカットを capability
と関連付ける方法は、実装する機能と、実際のユーザーのリクエストに含まれる言葉によって異なります。たとえば、ユーザーがアシスタントに「OK Google, ExampleApp でランニングを開始」と話しかけることで、フィットネス トラッキング アプリでランニングを開始するというシナリオがあるとします。その場合、capability
の exercise.name
パラメータに「ランニング」というエクササイズ エンティティを適切に定義すれば、アシスタントはショートカットを使用してそのインスタンスを起動できるでしょう。
ショートカットを App Actions に関連付ける方法について詳しくは、App Actions の概要をご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-27 UTC。
[null,null,["最終更新日 2025-08-27 UTC。"],[],[],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)."]]