Google Assistant voice search integration doesn't work with multiple words

3

In my Android project we recently added Voice Search following the documentation. It works fine, however only when searching one word. It doesn't seem to be an intended behaviour since in Google's examples they search for "trips to Maui".

We've tried many search commands on different devices using Google Assistant app (latest version), as well as launching via adb.

So, what works for us: "Ok Google, search for chocolate on {ourApp}".

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

Result: app is launched on proper screen with proper query

What doesn't work though: "Ok Google, search for ice cream on {ourApp}".

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

Result: Google Assistant displays web search results and via adb we get:

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) }

This looks as if the command was not proper though, as system recognises "cream" as package name. The result is the same even if we explicitly add package name to the adb command.

Our integration code:

<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>

And then in SearchResultsActivity:

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

How to achieve multiple-words search using Google Assistant?

android
google-voice-search
asked on Stack Overflow Jan 21, 2019 by maya_t

1 Answer

1

I can't tell you why (documentation not found), but spaces need to be escaped.

Therefore, this is your fixed example:

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

As a workaround, I wrote the following script (named send-search.sh):

inputQuery=$(printf %q "$1")
adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query "$inputQuery"

This is how you run it:

sh send-search.sh "ice\ cream"
answered on Stack Overflow Jul 29, 2019 by gianlucaparadise

User contributions licensed under CC BY-SA 3.0