Private vibrator Mvibrator;
1, get the handle of the vibration service
Mvibrator = (Vibrator) getsystemservice (Vibrator_service);
or Mvibrator = (vibrator) getapplication (). Getsystemservice (Service.vibrator_service);
Start shaking with two interfaces
1. Mvibrator.vibrate (2000);//vibration specified time, data type long, in milliseconds, 1/1000 seconds per millisecond
2. Mvibrator.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 second parameter is the vibration time. The parameters in turn 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.
2. Remove Vibration
Mvibrator.cancel ();//Cancel vibration, immediately stop vibration
Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake
3. Most important, permission settings
<uses-permission android:name= "Android.permission.VIBRATE"/>
How to use Android Vibrator