I'm trying to build an app that sparks into action following a pre-defined voice command from me, just like "OK Google". I want my device to launch a voice recognition intent just as soon as I give my "OK Google" type of message. already know how to launch such an intent:
if (isConnected()) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 4);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
startActivityForResult(intent, REQUEST_CODE);
} else {
Toast.makeText(getApplicationContext(), "Plese Connect to Internet", Toast.LENGTH_LONG).show();
}
However, right now, I'm only able to start this intent following a tap on a button. I want to be able to launch it without interacting with the UI. It may be possible to launch intent after intent in expectation of a vocal command, but it's not the desired approach.
Does anyone know how to do this?