How can I request the vibrate permission?

天大地大妈咪最大 提交于 2019-12-03 06:26:09

问题


How can I request the vibrate permission in my Android application?


回答1:


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

v.vibrate(new long[]{0, 500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500}, -1);



回答2:


Add the following in your AndroidManifest.xml:

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

More info on AndroidManifest permissions here

More info on list of permission here



来源:https://stackoverflow.com/questions/5775973/how-can-i-request-the-vibrate-permission

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