1

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

Frozen Crayon
  • 5,172
  • 8
  • 36
  • 71

2 Answers2

2

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.

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • This is not working for me. I have triple-checked everything, but just can't get this search query delivered to my app. Has anyone gotten this to work? – Chaitanya Nov 09 '14 at 05:24
  • 1
    Well... looks like the app needs to be published on Play Store: https://plus.google.com/+AndroidDevelopers/posts/afSRdDQiy1N - look for comments by Jarek Wilkiewicz. Going to try this next. – Chaitanya Nov 09 '14 at 05:54
  • @Chaitanya it worked for me. No need to publish app in the store. Do you have Google now on your phone? – Frozen Crayon Feb 06 '15 at 06:00
  • @Chaitanya: You need to add some meta data in the manifest as per this http://stackoverflow.com/questions/11699206/cannot-get-searchview-in-actionbar-to-work . For some reason, it's not clear in the Android dev documentation. – Arun Abraham Jun 20 '15 at 14:39
1

Also, the way we check for Intent also may be different. Only this worked for me. As the intent mentioned in the documentation is this.

Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())
        || "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
    externalQuery = intent.getStringExtra(SearchManager.QUERY);
    //String xquery = query;
}
sivag1
  • 4,734
  • 3
  • 32
  • 35
  • 2
    Putting 'com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())' is really not nice. Much better would be 'SearchIntents.ACTION_SEARCH.equals(intent.getAction())' – Mateusz Pryczkowski Jan 05 '16 at 09:10