Android Vibrator regulating vibration code example
- 2020-06-15 10:13:20
- OfStack
The vibration time can be adjusted by USING vibrate() of Vibrator; cancel() cancels the vibration.
<! - Vibration permission -->
<uses-permission android:name="android.permission.VIBRATE"/>
// Vibrator instantiation
private Vibrator mVibrator1;
mVibrator1=(Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
// Waiting for the 100ms After that, the vibration is separated by the values given by the array. Followed by the number of repetitions, -1 In order not to repeat, 01 Straight vibrating
mVibrator1.vibrate(new long[]{100,10,100,1000}, -1);
// Specified time for vibration
mVibrator1.vibrate(2000);
// Cancel the vibration
mVibrator1.cancel();