Android vibration effect

Source: Internet
Author: User

In setting a vibration event, you must know the duration of the command's vibration, the cycle of the vibration event, and the value set in Android, it is calculated in milliseconds (1000 milliseconds = 1 second). Therefore, you must note that if the set time value is too small, you will not feel it.

To shake a cell phone, you need to create a vibrator object to vibrate by calling the vibrate method. The Vibrator constructor has four parameters, the first three values are used to set the vibration size. Here, you can change the value to a small value, so that you can obviously feel the vibration difference, and the last value is the Set Vibration Time.

The following example sets different modes for each vibration. When repeat = 0, the vibration will continue. If repeat = −1, only one round of vibration will appear, after running, no action will be taken.

Import android. content. context; import android. OS. vibrator;/*** if an error is reported, go to androidmanifest. add the following statement ** <uses-Permission Android: Name = "android. permission. vibrate "/> * @ author Alex. xin **/public class vibrate {final static string tag = "gameengine"; vibrator; long [] pattern = {800, 50,400, 30 }; // set public vibrate (context) {vibrator = (vibrator) context. getsystemservice (context. vibrator_service);} public void playvibrate (INT type) {vibrator. vibrate (pattern, type); //-1 is not repeated. Non-1 is repeated starting from the specified subscript of pattern} public void stop () {vibrator. cancel ();}}

Try to change the vibration size multiple times. In long [], you can make more changes. The above program demonstrates the parameter usage.

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.