本文介绍了您如何在“初始设置"之后的“沉浸式"中自定义Glass上下文语音菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功填充了浸入玻璃器皿的上下文语音菜单,但我希望能够在onPreparePanel()或onCreatePanelMenu()中进行初始设置后更改 菜单,如下所述: 以编程方式填充的上下文"ok眼镜"菜单.

I've successfully populated the contextual voice menu of my glassware immersion but I want to be able to change the menu after the initial set up in onPreparePanel() or onCreatePanelMenu() as described here: Programmatically populated contextual "ok glass" menu.

理想情况下,在收到确定的"语音命令后将调用其中一个回调,但据我所知,它们都不是.结果,您对语音命令菜单的版本感到困惑,因为这是您第一次参加该活动.

Ideally one of the callbacks would be called after receiving the 'ok, glass' voice command but as far as I can tell, none of them are. Outcome, you're stuck with the version of the voice commands menu as it was the first time you cam into the activity.

到目前为止,唯一接近的黑客攻击是当我从设备上卸下GlassVoice.apk并设置手动VoiceListener时(如此处所述:).当检测到语音命令时,调用了onVoiceCommand,我尝试通过调用invalidateOptionsMenu()(无效)或getWindow().invalidatePanelMenu(WindowUtils.FEATURE_VOICE_COMMANDS)来强制刷新菜单.第二个看起来像是它试图拉出菜单,但随后又立即将其隐藏.

So far, the only hack that's come close was when I pulled the GlassVoice.apk off the device and set up a manual VoiceListener (as discussed here: Glass voice command nearest match from given list). When the voice command is detected an onVoiceCommand is called, I try to force a refresh of the menu by calling invalidateOptionsMenu() (no effect) or getWindow().invalidatePanelMenu(WindowUtils.FEATURE_VOICE_COMMANDS). This second one looks like it tries to pull up the menu but then instantly hides it again.

在活动的整个生命周期后期如何动态更改上下文语音菜单?

How can I dynamically change the contextual voice menu later on in the lifetime of the activity?

推荐答案

我实际上只是编写了一个示例应用程序,这对我来说很好用.

I actually just wrote a sample app and this is working fine for me.

请确保使用onCreatePanelMenu()创建语音菜单并选中

Be sure to use onCreatePanelMenu() to create the voice menu and check

if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS || 
    featureId == Window.FEATURE_OPTIONS_PANEL) ...

为触摸菜单和语音菜单同时扩展菜单.

to inflate the menu for both touch menu and voice menu.

要刷新两者,请确保同时调用invalidateOptionsMenu()getWindow().invalidatePanelMenu(WindowUtils.FEATURE_VOICE_COMMANDS)刷新触摸菜单,并同时getWindow().invalidatePanelMenu(WindowUtils.FEATURE_VOICE_COMMANDS)刷新语音菜单.我只是在第一个菜单项选择项上翻转了一个布尔值,用于确定是对旧菜单还是对新菜单进行夸大.

To refresh both, in onMenuItemSelected(), make sure to call both invalidateOptionsMenu() to refresh the touch menu and getWindow().invalidatePanelMenu(WindowUtils.FEATURE_VOICE_COMMANDS) to refresh the voice menu. I just flipped a boolean on the first menu item selection, which I used to determine whether an old or new menu should be inflated.

您正在运行什么版本的Glass?

What version of Glass are you running on?

这篇关于您如何在“初始设置"之后的“沉浸式"中自定义Glass上下文语音菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:55