How can I create a Submenu for Google Glass dynamically in Code? I want to select an User with Voice Commands like “Select User” -> “Ben”. The User-Data is loaded from a DB, so an XML menu isn't possible. This example works for navigation with swipe gestures:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
SubMenu sbm = menu.addSubMenu(Menu.NONE, 1, menu.NONE, "Select User");
sbm.add(Menu.NONE, 2, menu.NONE, "Ben");
sbm.add(Menu.NONE, 3, menu.NONE, "Ted");
return super.onPrepareOptionsMenu(menu);
}
Now I want to use the same with voice commands in the:
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
menu.clear();
SubMenu sbm = menu.addSubMenu(Menu.NONE, 1, menu.NONE, "Select User");
sbm.add(Menu.NONE, 2, menu.NONE, "Ben");
sbm.add(Menu.NONE, 3, menu.NONE, "Ted");
return super.onPreparePanel(featureId, view, menu);
}
But the Glass didn't recognize the voice commands. I hope anyone knows an solution and how can I catch the result? Because the following listing doesn't work for this solution.
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS || featureId == Window.FEATURE_OPTIONS_PANEL) {
switch (item.getItemId()) {
case 1:
...
many thanks in advance for any solution!
This works fine if I put similar code in onCreatePanelMenu()
. Since you are using unlisted voice commands , did you include the following permission in your manifest?
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.