Vibrator
Public classMainactivityextendsActivity {PrivateVibrator Vibrator; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Vibrator=(Vibrator) Getsystemservice (Vibrator_service); } Public voidClick (View view) {//vibrator.vibrate (+);//vibration 2sVibrator.vibrate (New Long[] {3000, 100, 100, 1000}, 1); }}
Code explanation
- Handle to get vibrate service
Vibrator = (Vibrator) getsystemservice (Vibrator_service);
Or
Vibrator = (Vibrator) getapplication (). Getsystemservice (Service.vibrator_service);
- Start shaking with two interfaces
Vibrator.vibrate (2000); // vibration specified time, data type long, in milliseconds, 1/1000 seconds per millisecond
Vibrator.vibrate (newlong[]{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.
Vibrator.cancel (); // Remove vibration, stop shaking immediately
Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake.
<android:name= "Android.permission.VIBRATE"/>
I'm the dividing line of the king of the Land Tiger.
Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
Vibrator Vibration. zip
Reprint Please specify source: Http://www.cnblogs.com/yydcdut