Skip to content Skip to sidebar Skip to footer

Is It Possible To Using Voice Commands For Navigating Instead Of Using Swipe Gesture?

Hi, there Currently, I'm develop an immersion app to provide a text on screen and user can swipe_right to go another one. Actually, It adapt from sample immersion pattern called c

Solution 1:

Here, It is my solution. Hope this might helped someone who looking for.

I used Contextual voice commands to provide 'Next', 'Save' and 'Exit' commands for an user. you can go to this document from google dev site to see the ideas of doing this.

I have my layout activity to show some TEXT, so I put this code structure. in my layout activity

//contextual voice commandimport com.google.android.glass.view.WindowUtils;
import android.view.Menu;
import android.view.MenuItem;


@OverridepublicbooleanonCreatePanelMenu(int featureId, Menu menu) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
        getMenuInflater().inflate(R.menu.main, menu);
        returntrue;
    }
    // Pass through to super to setup touch menu.returnsuper.onCreatePanelMenu(featureId, menu);
}

@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    returntrue;
}

@OverridepublicbooleanonMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
        switch (item.getItemId()) {

            case R.id.save_menu_item:
                Log.d("Contextual", "go save checks");  
                break;
            case R.id.next_menu_item:
                Log.d("Contextual", "go next checks");                    
                break;
            case R.id.exit_menu_item:
                Log.d("Contextual", "go exit checks");                    
                break;
            default:
                returntrue;
        }

        returntrue;
    }
    returnsuper.onMenuItemSelected(featureId, item);
}                                                                                                                

Don't forget to declare this line getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS); to your onCreate(); before your setContentView().

Next thing, I created 'menu folder' and main.xml inside its to provide my item selection. Like this

<menuxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/next_menu_item"android:title="@string/next"></item><itemandroid:id="@+id/save_menu_item"android:title="@string/save_this"></item><itemandroid:id="@+id/exit_menu_item"android:title="@string/exit"></item>

and my strings.xml file.

<resources>
   <string name="next">next</string>
   <string name="save_this">save</string>
   <string name="exit">exit</string>
</resources>

put this line <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />

to your AndroidMenifest.xml.

and it works fine for me !

Post a Comment for "Is It Possible To Using Voice Commands For Navigating Instead Of Using Swipe Gesture?"