Use the Vibrator class to write Android vibration in detail steps

Source: Internet
Author: User

in the Androidmainfest.xml declaring vibration permissions in a file

<uses-permission android:name= "Android.permission.VIBRATE"/>


Get mobile phone vibration services through system services, such as

Vibrator vibrator= (Vibrator) Getsystemservice (Vibrator_service)

Get vibration service after detection Vibrator is present, as

Vibrator.hasvibrator ();

returns false if there is true

Make appropriate calls based on actual needs, such as

Vibrator.vibrator (long milliseconds);

Start Vibrator with the above code for a duration of milliseconds milliseconds ( ms =1 seconds)

Vibrator.vibrator (long[] pattern, int repeat);

This pattern repeat ( repeats ) starts the vibrator ( Vibration ). Use pattern in the following form :

New Long[]{a1,a2,a3,a4 ...}

In the above format, where a group of two groups, such as A1 and A2 , is a group,A3 and A4 , The previous representative of each group waits for how many milliseconds to start the vibrator, and the latter represents How many milliseconds the vibrator continues to stop, then reciprocating. Repeat represents the number of repetitions, when it is 1 , that does not repeat only once in pattern mode


Stop Vibration

Vibrator.cancel ();

Use the Vibrator class to write Android vibration in detail steps

Related Article

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.