【问题标题】:Google Actions does not work from OK Google. my app is not recognisedOK Google 无法使用 Google 操作。我的应用无法识别
【发布时间】:2019-12-24 14:54:28
【问题描述】:

我从 google 下载了这个基本示例: 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

现在我这样做了,但这只会给我 Google 搜索响应,它不会像 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.'

知道为什么吗?

【问题讨论】:

    标签: android actions-on-google app-actions


    【解决方案1】:

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

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

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

    【讨论】:

    • 非常感谢,明天上班试试。所以这意味着,没有必要使用 console.actions.google.com 和 dialogflow? :D
    • 如果您使用的是内置应用操作,则不会。让我知道这是否适合你:)
    • console.actions.google.com 仅适用于在任何 Google 助理设备上运行的对话操作。您询问的是应用操作,这些操作用于启动/深度链接到 Android 应用。
    • @Sonia 我在问题中添加了一些额外信息,但仍然无法正确识别命令
    • @Sonia 我已经接受了这个作为答案,因为现在该应用程序确实获得了深层链接,并且它确实设法使用了这些操作。我找到了这个列表,其中包含每种类型的所有必需/可选参数:developers.google.com/actions/reference/built-in-intents 我将对其进行更多研究,以确定我应该为我的案例使用哪一个。我需要按名称获取用户的可寻址,然后拨打他的号码。如果有人对使用它有任何建议,我全神贯注。非常感谢到目前为止的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 2014-03-14
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多