I am studying how the android.speech package works and I noticed that most of the extras used with the intent RecognizerIntent.ACTION_WEB_SEARCH are ignored by the speech recognizer.
- If I set a language using the
RecognizerIntent.EXTRA_LANGUAGEextra, the specified language is ignored, but the default language of the device is always used. - If I set a text using the
RecognizerIntent.EXTRA_PROMPT, this text is not displayed. - If I start the speech recognition activity using
startActivityForResultmethod, then the speech recognizer callsonActivityResult, but the second argument (theresultCode) is alwaysRESULT_CANCELEDand the third argument (the dataIntent) is alwaysnull. This behavior is probably due to the fact that the purpose of this type of intent is to perform a search on the web. For the same reason, if I set the maximum number of results usingRecognizerIntent.EXTRA_MAX_RESULTS, the specified value is ignored.
I found this behavior, but the official documentation says that these options can also be used for the ACTION_WEB_SEARCH intent.
Why does the actual behavior of the voice recognition system differ from what is stated in official documentation?
I think you are using the wrong action. Instead of
ACTION_WEB_SEARCH, useACTION_RECOGNIZE_SPEECH.If you do,
onActivityResultwill behave as you expect and your Activity will be in control of interpreting the recognition results.By the way, when you set ACTION_WEB_SEARCH, you delegate handling of the results to Android. Based on what the user says, Android might start a web browser or it might start an email (if the user says “email”). Because of this it makes sense that your Activity does not receive any useful information, although I think it should still take into account RecognizerIntent.EXTRA_LANGUAGE.