Make the wearable vibrate from within an android wear app [closed]

做~自己de王妃 提交于 2019-12-03 06:02:58

问题


I'm writing a simple wearable app to my LG watch that sends vibrations to the watch on constant intervals and show some mock data.

Although I've looked for an answer, I could't find a way to make the watch vibrate. Any help would be appriciated.


回答1:


@Drew, thank you!

If anyone else is interested, here's a code snippet to demonstrate a vibration on your watch:

  • Add the following line to your AndroidManifest.xml:

    <uses-permission android:name="android.permission.VIBRATE"/>
    
  • In your code:

            Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
            long[] vibrationPattern = {0, 500, 50, 300};
            //-1 - don't repeat
            final int indexInPatternToRepeat = -1;
            vibrator.vibrate(vibrationPattern, indexInPatternToRepeat);
    


来源:https://stackoverflow.com/questions/26192475/make-the-wearable-vibrate-from-within-an-android-wear-app

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