Tom Tom - 2 months ago 25
Android Question

Android Wear 5.1 wrist gesture API?

Android 5.1.1 for wearables introduced the ability to dimiss notifications by rotating/flicking your wrist. Is this API exposed for developers to use? I'm unable to find any information on this, and their wearables developer site does not seem to have been updated.

Answer

It seems a bit late but this looks like what you exactly wanted.

Although pushing, raising, shaking gesture is not available, flicking wrist out and in gesture is available.

Each wrist gesture is mapped to an int constant from the KeyEvent class, as shown in the following table:

Flick wrist out: KEYCODE_NAVIGATE_NEXT, This key code goes to the next item.

Flick wrist in: KEYCODE_NAVIGATE_PREVIOUS, This key code goes to the previous item.

You can handle the event like this: (example code from developer document)

public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
   case KeyEvent.KEYCODE_NAVIGATE_NEXT:
    // Do something that advances a user View to the next item in an ordered list.
    return moveToNextItem();
   case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:
    // Do something that advances a user View to the previous item in an ordered list.
    return moveToPreviousItem();
  }
  // If you did not handle it, let it be handled by the next possible element as deemed by the Activity.
  return super.onKeyDown(keyCode, event);
 }
Comments