How to implement Voice search to SearchView

In case you have a SearchView and not a SearchActivity you can do these two steps to solve such problem:

  1. Declare searchable settings in the manifest.xml inside activity's tags like this:

    <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />

  2. Then associate searchable settings with the SearchView in your activity class (i.e. in onCreateOptionsMenu() methods) like this:

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) findViewById(R.id.search); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

For more information see docs.


In your res/xml folder, you should have a searchable file (usually called searchable.xml).

Within the <searchable /> element in that file, you should add this attribute:

android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"

There are other voice-related attributes (currently voicePromptText, voiceLanguageModel and voiceLanguage) which are all described here.


You can check out the documentation here

Update: If your SearchActivity is the same one, you can override onNewIntent and handle the Search intent there. Also make your activity as singleTop, that way only one instance of the activity will stay on top.

Hope this helps and please do notify if you find a solution.

Cheers!