Search code examples
androidsearchandroid-intentandroid-searchmanagergoogle-now

Receive search from Google Now


So I tried to implement this - The fastest route between voice search and your app

What i have so far is...

In manifest:

<activity android:name=".MainActivity">
<intent-filter>
    <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

In MainActivity:

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        editText.setText(query);

}

If I type my app name in Google Now, the app is shown. If I open it nothing happens, so I didn't receive the search term (the app name).

How do I implement like how the post has described "Ok Google, search pizza on MyApp"?


Solution

  • Per the blog post, queries are in the format:

    Ok Google, search pizza on Eat24

    Ok Google, search for hotels in Maui on TripAdvisor

    You'll note the bolded portion is the search term your app receives when a successful voice search in the correct format is sent to your app.