我如何申请振动许可?

时间:2021-05-03 18:18:54

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


23  

Add the following in your AndroidManifest.xml:

在AndroidManifest.xml中添加以下内容:

<uses-permission android:name="android.permission.VIBRATE" />

More info on AndroidManifest permissions here

有关AndroidManifest权限的更多信息,请点击此处

More info on list of permission here

有关此权限列表的更多信息

#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


23  

Add the following in your AndroidManifest.xml:

在AndroidManifest.xml中添加以下内容:

<uses-permission android:name="android.permission.VIBRATE" />

More info on AndroidManifest permissions here

有关AndroidManifest权限的更多信息,请点击此处

More info on list of permission here

有关此权限列表的更多信息