在 Android Wear 应用程序中使可穿戴设备振动
问题描述:
我正在为我的 LG 手表编写一个简单的可穿戴应用程序,它会向手表发送振动以恒定间隔显示一些模拟数据.
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.
答
@Drew,谢谢!
如果其他人有兴趣,这里有一个代码片段来演示手表上的振动:
If anyone else is interested, here's a code snippet to demonstrate a vibration on your watch:
将以下行添加到您的 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);