Heartbeat Shock Vibrator Use

Source: Internet
Author: User

Device vibrator, can set the frequency of vibration, simulating the vibration of the heartbeat.

There are two ways to get a device vibrator:

Vibrator = (Vibrator) getsystemservice (Vibrator_service);

Vibrator = (Vibrator) getapplicationcontext (). Getsystemservice (Service.vibrator_service);


There are two ways to turn on the set vibration:

The first type:

vibrator.vibrate (+); Direct Vibration 1000 ms, no waiting time

The second type:

Simulates the frequency of vibrations using an array.

long[] pattern = { ----; {Wait time, vibration time, wait time, vibration time ...}
vibrator.vibrate (Pattern,-1); -1 not repeat, non-1 to start repeating the specified subscript from pattern

First parameter: pattern: Specify the frequency of the vibration, wait 50 milliseconds first, shake 30 milliseconds, wait 60 milliseconds, shake 30 milliseconds ..... has been shaking down this frequency.

The second parameter: <0: Normally set to-1, which means that the frequency is only shaken once, waits 50 milliseconds, and vibrates for 30 milliseconds.

Greater than or equal to 0, but not >=pattern.length, that is, 0<=x<pattern.length, otherwise reported Java.lang.ArrayIndexOutOfBoundsException Exception


Remove Vibration:

Vibrator.cancel ();

Finally, I forgot to add the permissions in the Androidmanifest.xml file:

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



Heartbeat Shock Vibrator Use

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.