1

我从谷歌下载了这个基本示例: https ://github.com/actions-on-google/appactions-fitness-kotlin

现在,如果我这样做:

adb shell am start -a android.intent.action.VIEW -d "https://fit-actions.firebaseapp.com/start"

它将启动我的应用程序。并且深度链接正在被识别。该示例表明我可以通过在 Google Assistant 中说来做到这一点:

Start running in fit actions

现在我这样做了,但这只会给我谷歌搜索响应,它不会像 adb shell 命令一样启动我的应用程序。我确实更改了包名称,以便它符合我的google-services.json文件。

我究竟做错了什么?

这就是我的清单中的内容:

  <activity
        android:name=".activity.MainActivity"
        android:configChanges="orientation"
        android:exported="true"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize|stateUnchanged">
        <!-- Required to support search action intents from Google Search -->
        <intent-filter>
            <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>

            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

        <!-- Define your supported deeplinks -->
        <intent-filter
            android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="com.package.android"
                android:scheme="https"/>
        </intent-filter>
    </activity>

这是我的actions.xml

 <?xml version="1.0" encoding="utf-8"?><!--

<actions>

<!-- This file describes the supported actions by this app -->

<action intentName="actions.intent.START_EXERCISE">

    <!-- Each action requires at least one fulfillment that defines how the app will handle this action -->
    <!-- Define the urlTemplate in the format you define your deeplinks in AndroidManifest.xml -->

    <fulfillment urlTemplate="https://com.package.android/start{?exerciseType}">

        <!-- Define how the actions parameters (intentParameter) is mapped in the urlTemplate above -->

        <parameter-mapping
            intentParameter="exercise.name"
            urlParameter="exerciseType"/>

    </fulfillment>

    <!-- We can define our custom inline inventory, mapping a parameter to an entity set reference -->

    <parameter name="exercise.name">
        <entity-set-reference entitySetId="ExerciseEntitySet"/>
    </parameter>

</action>

<action intentName="actions.intent.STOP_EXERCISE">
    <fulfillment urlTemplate="https://com.package.android/stop"/>
</action>

<action intentName="actions.intent.GET_EXERCISE_OBSERVATION">

    <!-- You can define the fulfillment mode, it can be SLICE or DEEPLINK -->
    <!-- When slice is used, make sure you are supporting slices in your app -->
    <!-- Also, not that the urlTemplate must be of the style content://{slice_provider_authority}/... -->

    <fulfillment
        fulfillmentMode="actions.fulfillment.SLICE"
        urlTemplate="content://com.package.android.FitSliceProvider/stats{?exerciseType}">

        <!-- If a parameter is set as required, the action will only be fulfilled if the parameter is found -->
        <!-- That's why a fallback urlTemplate needs to be provided for such case. -->

        <parameter-mapping
            entityMatchRequired="true"
            intentParameter="exerciseObservation.aboutExercise.name"
            required="true"
            urlParameter="exerciseType"/>

        <!-- Note, that for the parameter above we are setting entityMatchRequired="true" -->
        <!-- This tells the Assistant to only use the entity set values to map this parameter -->
        <!-- Meaning that even if the assistant know how to identify the exercise (i.e "Climbing") -->
        <!-- if it's not defined in our entity set, the parameter won't be use. -->

    </fulfillment>

    <!-- In case the exercise name is not found we fallback to the stats deep-link inside the app -->

    <fulfillment
        fulfillmentMode="actions.fulfillment.DEEPLINK"
        urlTemplate="https://com.package.android/stats"/>

    <!-- Same as the first action, we map the parameter name with out supported entity set. -->

    <parameter name="exerciseObservation.aboutExercise.name">
        <entity-set-reference entitySetId="ExerciseEntitySet"/>
    </parameter>

</action>

<!-- Defines an entity set with our supported entities -->

<entity-set entitySetId="ExerciseEntitySet">

    <!-- For each entity you can specify the name, alternate names and the identifier -->
    <!-- The identifier is the value that will be added to the action uri. -->
    <!-- For our sample we map the supported entities with the class FitActivity.Type  -->

    <entity
        name="@string/activity_running"
        alternateName="@array/runningSynonyms"
        identifier="RUNNING"/>
    <entity
        name="@string/activity_walking"
        alternateName="@array/walkingSynonyms"
        identifier="WALKING"/>
    <entity
        name="@string/activity_cycling"
        alternateName="@array/cyclingSynonyms"
        identifier="CYCLING"/>
</entity-set>

如果我尝试应用操作测试工具 v2.00,它不会找到该应用。练习也总是使用http://schema.googleapis.com回到这种格式

在此处输入图像描述

编辑:

设置如下操作后:

<actions>
<action intentName="actions.intent.OPEN_APP_FEATURE">
    <fulfillment urlTemplate="https://www.xelion.com/start{?feature}">
        <parameter-mapping
            intentParameter="featureType"
            urlParameter="feature"/>
    </fulfillment>

    <parameter name="featureType">
        <entity-set-reference entitySetId="EntitySet"/>
    </parameter>
</action>

<entity-set entitySetId="EntitySet">

    <!-- For each entity you can specify the name, alternate names and the identifier -->
    <!-- The identifier is the value that will be added to the action uri. -->
    <!-- For our sample we map the supported entities with the class FitActivity.Type  -->
    <entity
        name="@string/action_call"
        alternateName="@array/callSynopsis"
        identifier="CALL"/>

</entity-set>

在应用操作测试工具中按下更新预览时,我得到了这个:

App Actions Test Tool v2.0.0
        Preview Creation Error
        Status Code: 400
        Message: Precondition check failed.
        - Parameter name 'featureType' is invalid for intent 'actions.intent.OPEN_APP_FEATURE.'
        - Parameter name 'featureType' is invalid for intent 'actions.intent.OPEN_APP_FEATURE.'

知道为什么吗?

4

1 回答 1

2

您需要首先使用 App Actions Test Plugin 触发操作: https ://plugins.jetbrains.com/plugin/12322-app-actions-test-tool

安装插件后,您会在“工具”下找到它,您可以为您的应用程序 + 参数定义一个调用名称。

从那时起,您可以使用“Ok Google”触发它。

于 2019-08-19T15:54:35.593 回答