Widget.SearchView does not show MIC button for voice search in android

I have a seachview file in a layout file called activity_products_final

<android.support.v7.widget.SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" android:queryHint="Search.."> </android.support.v7.widget.SearchView> </LinearLayout> 

Activity:

 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_products_final); searchView = (android.support.v7.widget.SearchView) findViewById(R.id.searchView); searchView.setIconified(false); searchView.onActionViewExpanded(); searchView.clearFocus(); searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (adapter != null) filterData(query); return false; } @Override public boolean onQueryTextChange(String query) { if (adapter != null) filterData(query); return false; } }); ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchView.setQuery("", false); searchView.clearFocus(); //collapseAll(); } }); } 

manifest file

 <activity android:name=".ActivityProductList" android:configChanges="orientation|screenSize" android:label="@string/title_activity_products" android:launchMode="singleTop" android:parentActivityName=".ActivityStartShopping" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> 

XML / search

 <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" > </searchable> 

According to google docs, I have to use android: voiceSearchMode = "showVoiceSearchButton | launchRecognizer" to show the MIC button.

I followed the document, but it does not show the MIC button for recording voice input.

Can someone help me with this?

+3
source share
5 answers

You need to create a SearchableConfiguration . Add this as searchable.xml to the xml resources folder:

 <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="search..." android:label="@string/app_name" <!-- the next line enables the voice button display --> android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"/> 
+2
source

Google services must be installed on your device or emulator.

For emulators that do not have G applications such as Genymotion, you must manually download Google applications. Available from opengapps.org/, use them with any kit and throw them into the emulator window, and then blink and reboot. May solve this.

0
source

I have a similar problem - on some devices icons with a microphone are installed, but not on others (for example, on a Samsung Galaxy S5 device).

I checked that this is not a problem with my code, confirming that the same problem occurs with the YouTube app.

I would recommend doing a web search to enable voice input for a specific device - or perhaps posting it for help / guidance on the Android / Samsung / etc user forum.

Also make sure that the Google app is installed on your device.

0
source

you need to set the search configuration in SearchView

 // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 

Then you need to process the onNewIntent () search results

 protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); searchView.setQuery(text, false); } } 
0
source

and in the onCreate method put this

 @Override protected void onNewIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); callSearch(query); Log.d(TAG, "onNewIntent: " +query); Toast.makeText(getApplicationContext(),query,Toast.LENGTH_LONG).show(); } } 
-1
source

All Articles