Private vibrator Vibrator;
Handle to get vibrate service
Vibrator = (Vibrator) getsystemservice (Vibrator_service);
or vibrator = (vibrator) getapplication (). Getsystemservice (Service.vibrator_service);
Start shaking with two interfaces
1. Vibrator.vibrate (2000);//vibration specified time, data type long, in milliseconds, 1/1000 seconds per millisecond
2. Vibrator.vibrate (New long[]{100,10,100,1000},-1);//vibrate in the specified mode.
Array parameter meaning: the first parameter is to wait for a specified time after the start of the vibration, the vibration time is the second parameter. The parameters in the back are the time to wait for vibrations and vibrations.
The second parameter is the number of repetitions, 1 is non-repeating and 0 is always vibrating
Remove vibrations
Vibrator.cancel ();//Cancel vibration, immediately stop vibration
Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake
Most importantly, increase permissions or run-time error
<uses-permission android:name= "Android.permission.VIBRATE"/>
Android Vibrator Use