Android 谷歌助理语音搜索集成不';我不能用多个词
在我的Android项目中,我们最近在文档后面添加了语音搜索。但是,它只在搜索一个单词时工作良好。这似乎不是有意的行为,因为在谷歌的例子中,他们搜索“毛伊岛之旅” 我们已经使用谷歌助手应用程序(最新版本)在不同的设备上尝试了许多搜索命令,并通过adb启动了这些命令 那么,什么对我们有效: “好的,谷歌,在{ourApp}上搜索巧克力” 结果:应用程序在适当的屏幕上启动,并进行适当的查询 但什么不起作用: “好的,谷歌,在{ourApp}上搜索冰淇淋。” 结果:Google Assistant显示web搜索结果,并通过adb获得:Android 谷歌助理语音搜索集成不';我不能用多个词,android,google-voice-search,Android,Google Voice Search,在我的Android项目中,我们最近在文档后面添加了语音搜索。但是,它只在搜索一个单词时工作良好。这似乎不是有意的行为,因为在谷歌的例子中,他们搜索“毛伊岛之旅” 我们已经使用谷歌助手应用程序(最新版本)在不同的设备上尝试了许多搜索命令,并通过adb启动了这些命令 那么,什么对我们有效: “好的,谷歌,在{ourApp}上搜索巧克力” 结果:应用程序在适当的屏幕上启动,并进行适当的查询 但什么不起作用: “好的,谷歌,在{ourApp}上搜索冰淇淋。” 结果:Google Assistant显示
Starting: Intent { act=com.google.android.gms.actions.SEARCH_ACTION pkg=cream (has extras) }
Error: Activity not started, unable to resolve Intent { act=com.google.android.gms.actions.SEARCH_ACTION flg=0x10000000 pkg=cream (has extras) }
这看起来好像命令不正确,因为系统将“cream”识别为包名。即使我们显式地将包名添加到adb命令,结果也是一样的
我们的集成代码:
<activity
android:name=".features.search.activities.SearchResultsActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
如何使用Google Assistant实现多词搜索?我无法告诉您原因(未找到文档),但需要转义空格
因此,这是您的固定示例:
adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION --es query 'ice\ cream'
作为解决方法,我编写了以下脚本(名为
sendsearch.sh
):
这是您运行它的方式:
sh send-search.sh "ice\ cream"
searchTerm = intent.getStringExtra(SEARCH_TERM_KEY) ?: intent.getStringExtra(SearchManager.QUERY).orEmpty()
adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION --es query 'ice\ cream'
inputQuery=$(printf %q "$1")
adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query "$inputQuery"
sh send-search.sh "ice\ cream"