Open In App

How to Create Google Glass Options Menu in Android?

Last Updated : 03 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Google Glass is a wearable device developed by Google that allows users to perform various tasks such as taking photos, recording videos, and sending messages. In this article, we will show you how to create a Google Glass options menu in Android.

Step By Step Implementation

Step 1: To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: In the MainActivity.java file, create a new method called “createOptionsMenu()”. This method will be used to create the options menu that will be displayed when the user taps on the touchpad of Google Glass.

Java




@Override public boolean onCreateOptionsMenu(Menu menu)
{
    // Inflate the menu; this adds items to the action bar
    // if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


Step 3: In the res/menu folder, create a new XML file called “main.xml”. This file will define the options that will be displayed in the menu.

XML




    <item
        android:id="@+id/menu_photo"
        android:title="Take Photo"
        android:showAsAction="always" />
    <item
        android:id="@+id/menu_video"
        android:title="Record Video"
        android:showAsAction="always" />
    <item
        android:id="@+id/menu_message"
        android:title="Send Message"
        android:showAsAction="always" />
</menu>


Step 4: In the MainActivity.java file, create new methods called “takePhoto()”, “recordVideo()”, and “sendMessage()”. These methods will be called when the user selects the corresponding menu items.

Java




public void takePhoto() {
    // code to take a photo
}
  
public void recordVideo() {
    // code to record a video
}
  
public void sendMessage() {
    // code to send a message
}


Step 5: In the MainActivity.java file, override the “onOptionsItemSelected()” method. This method will be called when the user selects a menu item.

Java




@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_photo:
            takePhoto();
            return true;
        case R.id.menu_video:
            recordVideo();
            return true;
        case R.id.menu_message:
            sendMessage();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}


That’s it! You have successfully created a Google Glass options menu in Android. When the user taps on the touchpad of Google Glass, the options menu will be displayed. The user can then select one of the options and the corresponding method will be called. It is worth noting that Google Glass is no longer being developed, and the device is no longer available for purchase.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads