Android App Action单语音指令无法传递发送者与描述问题排查
我在一个使用Android App Actions触发应用内功能的项目中,需要实现复杂的语音指令结构,目前已完成基础示例,但遇到参数组合传递的问题:
已在快捷方式能力中配置了actions.intent.GET_MESSAGE意图的4种app-widget组合,分别对应:
- 同时指定发送者和描述
- 仅指定发送者
- 仅指定描述
- 无参数
配置代码如下:
<capability android:name="actions.intent.GET_MESSAGE"> <app-widget android:identifier="APP_WIDGET_GET_MESSAGE_WITH_SENDER_AND_DESCRIPTION" android:targetClass="com.example.app.WidgetProvider" android:targetPackage="com.example.app"> <parameter android:required="true" android:name="message.description" android:key="description"/> <parameter android:required="true" android:name="message.sender.name" android:key="senderName"/> <extra android:name="hasTts" android:value="true" /> </app-widget> <app-widget android:identifier="APP_WIDGET_GET_MESSAGE_WITH_SENDER" android:targetClass="com.example.app.WidgetProvider" android:targetPackage="com.example.app"> <parameter android:required="true" android:name="message.sender.name" android:key="senderName"/> <extra android:name="hasTts" android:value="true" /> </app-widget> <app-widget android:identifier="APP_WIDGET_GET_MESSAGE_WITH_DESCRIPTION" android:targetClass="com.example.app.WidgetProvider" android:targetPackage="com.example.app"> <parameter android:required="true" android:name="message.description" android:key="description"/> <extra android:name="hasTts" android:value="true" /> </app-widget> <app-widget android:identifier="APP_WIDGET_GET_MESSAGE" android:targetClass="com.example.app.WidgetProvider" android:targetPackage="com.example.app"> <extra android:name="hasTts" android:value="true" /> </app-widget> </capability>
单独使用指令show me messages from john doe on action app(仅指定发送者)或show me the first message on action app(仅指定描述)时,功能正常,参数能传递到应用。但使用指令show me the first message from john doe on action app同时指定发送者和描述时,参数无法传递到应用,且Google Assistant无失败提示,Logcat也未找到相关报错。
请问是否存在参数组合使用的限制,或是指令格式不符合处理要求?
优化语音指令的表述清晰度
Google Assistant对参数的提取依赖自然语言的明确性,当前指令show me the first message from john doe中,Assistant可能无法区分the first message是message.description参数,还是对消息的泛指描述。可以尝试更明确的表述,比如:show me messages described as 'the first' from john doe on action appshow me the first message sent by john doe on action app
验证触发的app-widget实例
在WidgetProvider的处理逻辑中添加日志,打印接收到的senderName和description参数值,以及当前触发的app-widget标识符。这能确认是否触发了正确的、包含两个参数的app-widget,还是误匹配到了仅含单个参数的实例。检查意图参数的实体匹配规则
message.description对应的是消息的描述性内容,而the first message可能被Assistant解析为消息的排序属性(而非描述),导致无法映射到message.description参数。可以尝试使用更偏向“描述”的内容作为测试值,比如show me messages about 'meeting notes' from john doe on action app,看是否能成功传递两个参数。调整参数的required属性(临时测试)
暂时将第一个app-widget中的两个参数required属性改为false,测试是否能接收到部分参数,以此排查是否是参数必填校验导致的问题。如果能接收到参数,再改回true并优化指令表述。确认系统意图的参数兼容性
虽然官方文档未明确限制GET_MESSAGE意图的参数组合,但部分系统意图在实际解析时对多参数组合的支持有限。可以尝试自定义意图(而非使用actions.intent.GET_MESSAGE),配置对应的参数和训练短语,测试多参数组合的传递效果。
内容的提问来源于stack exchange,提问作者Stephan Koglin-Fischer

