How can I request the vibrate permission in my Android application?
如何在Android应用程序中请求振动权限?
2 个解决方案
#1
198
Here is the link to the reference
这是参考的链接
Add this to your manifest, as a direct child of the manifest
element:
将此添加到清单中,作为清单元素的直接子项:
<uses-permission android:name="android.permission.VIBRATE" />
This is how you let the phone Vibrate thru code:
这就是你让手机通过代码振动的方式:
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 300 milliseconds
v.vibrate(300);
For a more creative pattern try the star wars theme =D
对于更有创意的模式,请尝试星球大战主题= D.
v.vibrate(new long[]{0, 500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500}, -1);
#2
#1
198
Here is the link to the reference
这是参考的链接
Add this to your manifest, as a direct child of the manifest
element:
将此添加到清单中,作为清单元素的直接子项:
<uses-permission android:name="android.permission.VIBRATE" />
This is how you let the phone Vibrate thru code:
这就是你让手机通过代码振动的方式:
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 300 milliseconds
v.vibrate(300);
For a more creative pattern try the star wars theme =D
对于更有创意的模式,请尝试星球大战主题= D.
v.vibrate(new long[]{0, 500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500}, -1);