本文介绍了在 Android Wear 应用程序中使可穿戴设备振动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的 LG 手表编写一个简单的可穿戴应用程序,它会向手表发送振动以恒定间隔显示一些模拟数据.
I'm writing a simple wearable app to my LG watch that sends vibrations to the watchon 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);
这篇关于在 Android Wear 应用程序中使可穿戴设备振动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!