Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Search Voice

Jorge Coca
December 01, 2015

Android Search Voice

SPR Learning Lunch - Android Voice Search

Jorge Coca

December 01, 2015
Tweet

More Decks by Jorge Coca

Other Decks in Technology

Transcript

  1. Rules for a good search experience —You need to provide

    good content —It has to be fast —It has to be simple
  2. Voice Search —When entering text, allow users to either use

    the keyboard or their voice. —Let Android handle voice recognition —Voice search is a great feature, but very error prone (and sometimes frustating) —It submits directly what it is said (so no opportunities for second attempts) —Combine text search and voice search
  3. SearchView —It is built-in component in the Android framework —It

    lives in the Toolbar —When activated, turns your toolbar into a text input field —It can also provide historical results —Available in all Android versions (through AppCompat)
  4. @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater.inflate(R.menu.main_activity_options, menu); MenuItem searchItem

    = menu.findItem(R.id.action_search); SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { // Text has changed, apply filtering? return false; } @Override public onQueryTextSubmit(String query) { // Perform the final search } }); }
  5. Searchable Configuration —This is a configuration file for search settings:

    Info <searchable android:label="@string/app_name" android:hint="@string/search_hint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"/>
  6. Getting the search query Call this from onCreate() or onNewIntent().

    private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); } }