Search code examples
androidandroid-activitygoogle-glassgoogle-gdk

Disable contextual voice command in activity


I am calling this feature :

getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);

It should be easy but I can't find how hide / disable this feature once it is launch in my Activity. I would like the function to enable / disable the "Ok Glass" feature, then I will use it in my menu.

This GlassWare doesn't it perfectly, you can show or hide the "Ok Glass" at the bottom from the menu : Google Glass Chess


Solution

  • I think onPreparePanel is what you're looking for. It is called right before the panel window is shown, every time it is shown. For GDK, that's right after the activity is created and also when a user taps the touchpad and the menu appears.

    Return false when you want to disable the "Ok Glass":

    @Override
    public boolean onPreparePanel(int featureId, View view, Menu menu) {
        Log.v(TAG, "CityRideActivity#onPreparePanel");
        if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {            
            return false; // <-- disable "Ok Glass"
        }
        return super.onPreparePanel(featureId, view, menu);
    }
    

    I guess Google Glass Chess disables the voice menu when the user taps the touch pad but the developer uses a custom view for his menu.

    GDK doc has a brief explanation but quite helpful:

    (Optional) Override onPreparePanel(), checking whether or not WindowUtils.FEATURE_VOICE_COMMANDS is enabled. If enabled, this is where you can do other logic to set up the menu system, such as adding and removing certain menu items based on some criteria. You can also toggle contextual voice menus on (return true) and off (return false) based on some criteria.