android - 为什么我无法创建要求 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 烤意大利面”之类的话,它就可以了。为什么我不能有两个字符串???谢谢你的帮助
解决方案
我刚刚尝试使用您上面的示例复制该问题,但它按我的预期工作。这两个字段都包含在 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)
}
推荐阅读
- compilation - 跳转标签分析和生成是什么编译器技术?
- java - 为什么我不能使用我的代码从 excel 中获取值到列表中?
- python - 两个 3d 点之间的 Mayavi 弯曲箭头
- python - 如何确保正确配置 anaconda 环境以导入包
- javascript - 安装电子与安装电子生成器
- vue.js - 如何从 element-ui 中删除工具提示组件中的淡出过渡?
- java - 按钮单击事件在netbeans java中不起作用
- r - 是否可以在闪亮的应用程序(renderGrViz)中选择一个 graphviz 节点,然后链接到其他信息?
- scala - Scala 宏中的 Lambda 导致 NoSuchMethodError 异常
- haskell - 如何使用 Haskell 替换字符串中的多个单词?