Steps for setting mobile phone vibrations in Android (Android learning guide 3)

Source: Internet
Author: User

 

In Android, follow these steps:

 

A. Obtain the mobile phone vibration service through the system service. Vibrator vibrator = (Vibrator) getSystemService (VIBRATOR_SERVICE );

 

B. Check whether the vibrator exists after obtaining the vibration service:

 

Vibrator. hasVibrator ();

 

Checks whether the current hardware has a vibrator. If yes, true is returned. If no, false is returned.

 

C. Make appropriate calls based on actual needs,

 

Vibrator. vibrate (long milliseconds );

 

Start vibrator for milliseconds in milliseconds.

 

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

 

Start vibrator again in pattern mode. (Pattern is in the form of new long [] {arg1, arg2, arg3, arg4 ......}, take two groups, such as arg1 and arg2, as a group, and arg3 and arg4 as a group. The first one in each group represents how many seconds to wait to start vibrator, the last one indicates how many milliseconds the vibrator has stopped, and then it can be reciprocating. Repeat indicates the number of repetitions. If it is-1, it indicates that the operation is not repeated only once in the pattern format ).

 

Vibrator. cancel ();

 

Vibrator stops.

 

Note: The following permissions are required when using the vibration service: android. permission. VIBRATE

 


From tianshijianbing1989

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.