Book Image

Android Wearable Programming

By : Steven F. Daniel
Book Image

Android Wearable Programming

By: Steven F. Daniel

Overview of this book

Table of Contents (14 chapters)
Android Wearable Programming
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Receiving voice input within a notification


In this section, we will be taking a look at how we can use notifications that can allow the user to respond to these by simply using their voice. Since Android wearable devices don't contain a keyboard, a user can swipe on a notification and respond to the action using their voice, or simply by choosing from a list of options presented to them, and tapping on the item right from their Android wearable device.

To receive voice input within a notification, perform the following steps:

  1. Open the MainActivity.java file from within the Project Navigator window.

  2. Modify the onCreate(Bundle savedInstanceState) method and add the following highlighted code:

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // Clear all previous notifications and
            // generate new unique ids
            NotificationManagerCompat.from(this).cancelAll();
    
      ...