Device vibrator, can set the frequency of vibration, simulating the vibration of the heartbeat.
There are two ways to get a device vibrator:
Vibrator = (Vibrator) getsystemservice (Vibrator_service);
Vibrator = (Vibrator) getapplicationcontext (). Getsystemservice (Service.vibrator_service);
There are two ways to turn on the set vibration:
The first type:
vibrator.vibrate (+); Direct Vibration 1000 ms, no waiting time
The second type:
Simulates the frequency of vibrations using an array.
long[] pattern = { ----; {Wait time, vibration time, wait time, vibration time ...}
vibrator.vibrate (Pattern,-1); -1 not repeat, non-1 to start repeating the specified subscript from pattern
First parameter: pattern: Specify the frequency of the vibration, wait 50 milliseconds first, shake 30 milliseconds, wait 60 milliseconds, shake 30 milliseconds ..... has been shaking down this frequency.
The second parameter: <0: Normally set to-1, which means that the frequency is only shaken once, waits 50 milliseconds, and vibrates for 30 milliseconds.
Greater than or equal to 0, but not >=pattern.length, that is, 0<=x<pattern.length, otherwise reported Java.lang.ArrayIndexOutOfBoundsException Exception
Remove Vibration:
Vibrator.cancel ();
Finally, I forgot to add the permissions in the Androidmanifest.xml file:
<uses-permission android:name= "Android.permission.VIBRATE"/>
Heartbeat Shock Vibrator Use