Sunday 9 November 2014

Link your app with Google Voice Search

Google with Version 3.5 has come extended it's voice search functionality to include device apps in its search result.

Now Activate Google voice search by saying "OK Google" from anywhere within your app or from anywhere within the device.

You are only required to add few lines of code in your manifest file.

<activity android:name=".SearchableActivity">
    <intent-filter>
        <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>
Once manifest changes are done, your app will receive the SEARCH_ACTION intent containing the SearchManager.QUERY extra with the search expression.

Assuming your app as MyApp. You can:
Activate Google: Say "OK Google"
Start Search: Say "search xyz on MyApp" or "Search for hotels in India on MyApp".

Inside your activity, you get the search string i.e xyz, hotels :
String query = getIntent().getExtras().getString(SearchManager.QUERY);

This feature is available on English locale Android devices running Jelly Bean and above with the Google app v3.5 or greater.

Check this OK Google from any screen and also check official post.

No comments:

Post a Comment