The onActivityResult
method callback fires when the speech recognizer returns with the voice input intent. Note how we extract the spoken text and then call the GoogleApiClient
API if the voice command begins with one of our predefined contexts, namely home
or work
:
// This callback is invoked when the Speech Recognizer returns. // This is where you process the intent and extract the speech text from the intent. @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Constants.SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); spokenText = results.get(0); // Do something with spokenText Log.i(TAG, "Spoken Text = " + spokenText); if (spokenText.startsWith("home") || spokenText.startsWith("work")) { Log.i(TAG, "Creating Google Api Client"); mGoogleApiClient = new...