How to use Android Vibrator

Source: Internet
Author: User

Private vibrator Mvibrator;

1, get the handle of the vibration service
Mvibrator = (Vibrator) getsystemservice (Vibrator_service);
or Mvibrator = (vibrator) getapplication (). Getsystemservice (Service.vibrator_service);


Start shaking with two interfaces
1. Mvibrator.vibrate (2000);//vibration specified time, data type long, in milliseconds, 1/1000 seconds per millisecond
2. Mvibrator.vibrate (New long[]{100,10,100,1000},-1);//vibrate in the specified mode.
Array parameter meaning: the first parameter is to wait for a specified time after the start of the vibration, the second parameter is the vibration time. The parameters in turn 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.


2. Remove Vibration
Mvibrator.cancel ();//Cancel vibration, immediately stop vibration
Vibration is always shaking, if not cancel the vibration, even if the exit, will always shake


3. Most important, permission settings
<uses-permission android:name= "Android.permission.VIBRATE"/>

How to use Android Vibrator

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.