2

Here is my code

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_sample);

    }
 @Override
        public boolean onCreatePanelMenu(int featureId, Menu menu) {
            if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
            }
            // Pass through to super to setup touch menu.
            return super.onCreatePanelMenu(featureId, menu);
        }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        @Override
        public boolean onMenuItemSelected(int featureId, MenuItem item) {
            if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
                switch (item.getItemId()) {
                    case R.id.dogs_menu_item:
                        // handle top-level dogs menu item
                        break;
                    default:
                        return true;
                }
                return true;
            }
            // Good practice to pass through to super if not handled
            return super.onMenuItemSelected(featureId, item);
        }

I am trying to enable contextual menu, from my activity.. With the above code "ok glass" should be displayed on the bottom of my activity but it doesn't display.The version of glass I am using is 21.3.

Prasanna Aarthi
  • 3,439
  • 4
  • 26
  • 48

4 Answers4

4

Do you use any theme?

In the manifest, remove android:theme="@style/AppTheme".

For example, change

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

to

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">

After changing to the default theme, I guess you probably don't need requestWindowFeature(Window.FEATURE_NO_TITLE); and the " ok glass " should show up.

pt2121
  • 11,720
  • 8
  • 52
  • 69
1

Your code seems right, but have you tried to implement the menu ?

I am not sure but maybe if the correct Override function like onCreatePanelMenu are not there, contextual voice command cannot be activated.

Here are the documentation from Google : Contextual Voice command

Pull
  • 2,236
  • 2
  • 16
  • 32
  • You have no error and no other activity displayed before your activity_sample ? Maybe try to remove : requestWindowFeature(Window.FEATURE_NO_TITLE); – Pull Oct 10 '14 at 12:26
  • I don't have any error.. I have a service which displays a low frequency live card a contextual menu from here takes me to this activity. – Prasanna Aarthi Oct 10 '14 at 12:43
1

Before you publish your liveCard in your Service class you have to set this:

liveCard.setVoiceActionEnabled(true);
Cloud57
  • 66
  • 9
1

You code seems right :/

Have you tried using Cards for building Ui instead of using setContentView(R.layout.activity_sample);

May be thats causing this problem.

Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84