Search code examples
androidandroid-searchgoogle-now

How to programmatically initiate a Google Now voice search?


I want to start a Google Now voice search when the user presses a button. However, I can't find the Intent to start the search in the docs.

Does anybody know how to start activity for Google Now voice Search?


Solution

  • Use ACTION_RECOGNIZE_SPEECH:

    private static final int RECOGNIZER_REQ_CODE = 1234;
    
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    startActivityForResult(intent, RECOGNIZER_REQ_CODE);
    

    Please note that you have to use startActivityForResult() as startActivity() is not supported. See the above linked docs for details.