Wednesday, January 28, 2015

The fastest route between voice search and your app

A very cool feature you can add to your Android app is integrating with Google's voice search.

When enabled, your users will be able to say to their phone:

  "Ok Google, search for flights from NY to LA on MyCoolTravelApp"

The good news is this integration is very simple, and Eva is a perfect match to parse any text provided by the user.

3 small steps are necessary:

1. To AndroidManifest.xml  change the your Activity entry with:

            android:launchMode="singleTask"    >
           <action android:name=""/>
           <category android:name="android.intent.category.DEFAULT"/>

2. To your search activity - add:

protected void onNewIntent(Intent intent) {

3. at the end of onResume method add:

Intent intent = getIntent();
if ("".equals(intent.getAction())) {
         // search from Google Voice Search:
         // similar to clearing session and then handling voice-recognition results
         // When starting a new session you'd want to clear the chat screen
         String searchString = intent.getStringExtra(SearchManager.QUERY);|
         // Add the user chat and initiate an eva search
        eva.searchWithText(searchString, null, false);
        // clear the intent - it shouldn't run again when resuming
       onNewIntent(new Intent());

  1. If your search activity is not the top level activity in your app you may wish to setup a back stack - see the relevant Android documentation.
  2. The Google Voice integration will not work until you publish your app to the Play store with the updated AndroidManifest.
    To test it can send the intent via adb, for example:
    adb shell am start -a -e query Flights from NY to LA <app package name here>

No comments:

Post a Comment