Android--Vibrator

Source: Internet
Author: User

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.

    • Remove vibrations
Vibrator.cancel (); // Remove vibration, stop shaking immediately

Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake.

    • Permissions
<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.