Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Handle Voice Search? #24

Closed
goclixy-core opened this issue Feb 2, 2016 · 2 comments
Closed

How to Handle Voice Search? #24

goclixy-core opened this issue Feb 2, 2016 · 2 comments
Labels

Comments

@goclixy-core
Copy link

Thank you for the great SearchView.

I am having a problem with Voice Search. Your sample application does not include its working. Could you please explain its implementation?

@arimorty
Copy link
Owner

arimorty commented Feb 3, 2016

Hi,

There is no direct support for voice search. Instead, you have to implement it yourself by adding it as a MenuItem in xml and then respond to its clicks from within:

mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
      @Override
      public void onMenuItemSelected(MenuItem item) {                  

      }
   });

Please refer to Configure menu items section in README

@shivampip
Copy link

shivampip commented Feb 13, 2017

Here is a method to handle Voice Search

final int VOICE_SEARCH_CODE = 3012;

public void startVoiceRecognition() {
	Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
	intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
	intent.putExtra("android.speech.extra.PROMPT", "Sepeak Now");
	this.startActivityForResult(intent, VOICE_SEARCH_CODE);
}

 @ Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (requestCode == VOICE_SEARCH_CODE && resultCode == RESULT_OK) {
		ArrayList < String > matches = data
			.getStringArrayListExtra("android.speech.extra.RESULTS");
		searchView.setSearchText(matches.get(0));
	}
	super.onActivityResult(requestCode, resultCode, data);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants