【问题标题】:Google Assistant voice search integration doesn't work with multiple wordsGoogle Assistant 语音搜索集成不适用于多个单词
【发布时间】:2019-07-29 20:41:19
【问题描述】:

在我的 Android 项目中,我们最近在文档之后添加了语音搜索。它工作正常,但仅在搜索一个单词时。这似乎不是预期的行为,因为在 Google 的示例中,他们搜索“毛伊岛之旅”。

我们已经使用 Google Assistant 应用(最新版本)在不同设备上尝试了许多搜索命令,以及通过 adb 启动。

那么,什么对我们有用: “Ok Google,在 {ourApp} 上搜索巧克力”。

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION  --es query 'chocolate'

结果:应用程序通过正确的查询在正确的屏幕上启动

什么不起作用: “Ok Google,在 {ourApp} 上搜索冰淇淋”。

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION  --es query 'ice cream'

结果:Google Assistant 显示网页搜索结果,通过 adb 我们得到:

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>

然后在 SearchResultsActivity 中:

searchTerm = intent.getStringExtra(SEARCH_TERM_KEY) ?: intent.getStringExtra(SearchManager.QUERY).orEmpty()

如何使用谷歌助手实现多词搜索?

【问题讨论】:

    标签: android google-voice-search


    【解决方案1】:

    我无法告诉你原因(未找到文档),但需要转义空格。

    因此,这是您的固定示例:

    adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION  --es query 'ice\ cream'
    

    作为一种解决方法,我编写了以下脚本(名为 send-search.sh):

    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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 2012-10-05
      相关资源
      最近更新 更多