首页 > 解决方案 > 为什么我无法创建要求 2 个文本的自定义意图?

问题描述

我有一个自定义意图,即从 Google 助理接收 2 个文本参数。但助手不会启动我的应用程序。我只试过一个,它工作正常。问题是当我添加第二个文本参数时。我尝试过使用另一种数据类型并且它有效。例如,如果我要求一个文本和一个数字,效果很好。如果我要求文本和时间,它也有效。但是,如果我要求一个文本和一个文本,那么它不会。请问这里有什么帮助吗?这是我在 actions.xml 文件中的意图:

<action intentName="custom.actions.intent.MyName" queryPatterns="@array/MyExampleStrings">
   <!-- Define parameters -->
   <parameter name="textA" type="https://schema.org/Text" />
   <parameter name="textB" type="https://schema.org/Text" />

   <!-- Define fulfillment -->
   <fulfillment urlTemplate="https://my.site.com/{?FirstText,SecondText}">
      <parameter-mapping intentParameter="textA" urlParameter="FirstText" />
      <parameter-mapping intentParameter="textB" urlParameter="SecondText" />
   </fulfillment>
</action>

MyExampleStrings 类似于“使用 $textB 烘烤 $textA”,例如“用番茄烘烤意大利面”。

正如我之前所说,它适用于不同的数据类型。在下一个示例中,我更改了数字的第二个文本,它可以工作:

<action intentName="custom.actions.intent.MyName" queryPatterns="@array/MyExampleStrings">
   <!-- Define parameters -->
   <parameter name="textA" type="https://schema.org/Text" />
   <parameter name="textB" type="https://schema.org/Number" /> <--NUMBER!

   <!-- Define fulfillment -->
   <fulfillment urlTemplate="https://my.site.com/{?FirstText,SecondText}">
      <parameter-mapping intentParameter="textA" urlParameter="FirstText" />
      <parameter-mapping intentParameter="textB" urlParameter="SecondText" />
   </fulfillment>
</action>

在这种情况下,如果我说“用 4 烤意大利面”之类的话,它就可以了。为什么我不能有两个字符串???谢谢你的帮助

标签: androidactions-on-googleapp-actions

解决方案


我刚刚尝试使用您上面的示例复制该问题,但它按我的预期工作。这两个字段都包含在 intent?.data 字段中。所以,就我而言,它看起来像这样:

https://todo.myapp.com/custom-intents?FirstText=Example123&SecondText=Example222

您能否进一步详细说明您如何检索查询参数?

作为一般建议,活动中的 onCreate 函数中的日志语句应提供以下详细信息:

override fun onCreate(savedInstanceState: Bundle?) {
    Timber.tag(TAG).d("======= debugging data =========" + intent?.data)
}


推荐阅读