How can you make a phone vibrate on button press?

时间:2016-03-02 10:56:43

标签: java android xml android-studio

I want to create an Android on click function that will make the phone vibrate for 5 sec.

1 个答案:

答案 0 :(得分:2)

Try this out:

 Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
 v.vibrate(5000); // 5000 miliseconds = 5 seconds

And add the permision in AndroidManifest.xml

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

Read more here please, this is the duplicate and easily to be found: How to make an Android devide vibrate

相关问题