I want to add voice search function to my application. I'm populating a SearchView in SherlockActivity. But I can't find a solution to add voice search function to SearchView object.
Can you please give an advice, what do I need to do?
Code below :
public class MainActivity extends SherlockActivity {
private SlidingMenu slidingMenu;
private SlidingMenu slidingMenuRight;
private String mFilterArrays[];
public long lastScrollTime=0; /** En son kaydırma ne zaman yapıldı*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
//Create the search view
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Search...");
menu.add("Search")
.setIcon(R.drawable.ic_search_inverse)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
}
Mainfest
<activity
android:name="com.paea.bcp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.paea.bcp.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
Open the Google website on your desktop computer and you'll find a little microphone icon embedded inside the search box. Click the icon, say something and your voice is quickly transcribed into words.
How do you use Google Voice Search? Android Devices: Android users can turn on Google Voice Search anytime saying “OK Google“. You can use it to give voice commands to the device, find any information, and get directions.
Voice search is a technology that allows the user to use a voice command to perform a search on the Internet, a website or an application. The result of advances in speech recognition, this feature first appeared on smartphones, making it possible to replace the search bar.
It works through the automatic speech recognition (ASR) system that transforms voice signal into text. Then search engines like Google use the text as if it's a typical search query and proceed with what they do best—matching the search query with the right results.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With