With this code:
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
With differents ways (Button event, gesture, life cycle) I can call this method to open the Speech Input prompt as the same way like I've clicked in the microphone icon in the google search field. Ok, that's good.
But now, I need to call this method using a command voice. As the same way in google now, we say "Ok Google" and the Speech Input prompt appears. I want to do this inside my app. For example, I'm in the main activity and I say "hear me" and the method promptSpeechInput is called.
How can I do this?
Thanks for help.