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:
<activity android:name="com.yourcompany.YourSearchActivity" android:launchMode="singleTask" > <intent-filter> <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter></activity>
2. To your search activity - add:
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); }
3. at the end of onResume method add:
Intent intent = getIntent(); if ("com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) { // search from Google Voice Search: // similar to clearing session and then handling voice-recognition results eva.resetSession(); eva.stopSearch(); // When starting a new session you'd want to clear the chat screen clearChatHistory(); String searchString = intent.getStringExtra(SearchManager.QUERY);| // Add the user chat and initiate an eva search addUserChat(searchString); eva.searchWithText(searchString, null, false); // clear the intent - it shouldn't run again when resuming onNewIntent(new Intent()); }
Note:
- 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.
- 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 com.google.android.gms.actions.SEARCH_ACTION -e query Flights from NY to LA <app package name here>
No comments:
Post a Comment