1, get the handle of vibration service
Vibrator = (Vibrator) getsystemservice (Vibrator_service);
Or
Vibrator = (Vibrator) getapplication (). Getsystemservice (Service.vibrator_service);
2. start shaking with two interfaces
Vibrator.vibrate (2000);//vibration specified time, data type long, in milliseconds, 1/1000 seconds per millisecond
Vibrator.vibrate (new long[]{100,10,100,1000},–1);
Vibrate according to 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.
3. Remove Vibration
Vibrator.cancel ();//Cancel vibration, immediately stop vibration
Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake.
4. Permissions
<uses-permission android:name= "Android.permission.VIBRATE"/>
Reference: http://blog.csdn.net/caesardadi/article/details/8251933 and http://www.2cto.com/kf/201407/316511.html
Android--vibrator--Shake Service