Android Wear 5.1 wrist gesture API?

徘徊边缘 提交于 2019-12-10 08:48:58

问题


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.


回答1:


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);
 }



回答2:


No, there is currently no wrist gesture API for Wear 1.0 devices and that is why the developer site does not mention wrist gestures.



来源:https://stackoverflow.com/questions/30993471/android-wear-5-1-wrist-gesture-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!