Search code examples
androidgoogle-glassgoogle-gdk

Google Glass : return to voice_trigger / voice_prompt from the Activity


I am new to Glass development, I have a simple application

Ok Glass => Dictionary (voice_trigger) => Say a word to search (voice_prompt) => MyActivity (app)

If I do a SWIPE_DOWN, I go back to the first view : Ok Glass. From my Activity, I would like to launch another research with a gesture, and go back to the voice_prompt view, without saying "Ok Glass" and "Dictionary".

Is it possible or do I need to avoid voice_prompt is this case ?

Thanks


Solution

  • In your activity, you should be able to do something like:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK) {
            Log.i(TAG, "BACK PUSHED");
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            startActivityForResult(intent, SPEECH_REQUEST);
            return true;
        }
    
        return super.onKeyDown(keyCode, event);
    }
    

    By doing this, you stop the default handler for the swipe down and set your own, which causes the speech recognition activity to appear (https://developers.google.com/glass/develop/gdk/voice#starting_speech_recognition).