Android mobile phone vibrate

Source: Internet
Author: User

Package chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. media. audiomanager; <br/> Import android. OS. bundle; <br/> Import android. OS. vibrator; <br/> Import android. view. view; <br/> Import android. widget. toast; <br/> Import android. widget. togglebutton; </P> <p> public class vibrateactivity extends activity {</P> <p> private togglebutton button; <br/> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> // todo auto-generated method stub <br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. vibrate); </P> <p> button = (togglebutton) findviewbyid (R. id. togglebutton1); <br/> button. setonclicklistener (new view. onclicklistener () {</P> <p> @ override <br/> Public void onclick (view v) {<br/> Boolean flag = button. ischecked (); <br/> If (FLAG) {<br/> // obtain the vibrate object <br/> vibrator = (vibrator) getsystemservice (vibrator_service ); <br/> // vibrator. vibrate (3000); <br/> // set the vibrate vibration cycle <br/> vibrator. vibrate (New long [] {1000,2000, 3000,4000}, 0); <br/> toast. maketext (vibrateactivity. this, "shaken", toast. length_long ). show (); <br/>}< br/> else {</P> <p >}< br/> }); </P> <p >}< br/>


Android. OS. vibrate represents the mobile phone vibrator. The usage is very simple. Get the example using the getsystemservice () method, and then call the vibrate method to implement vibration.

To use this vibrator, you must specify the permission in androidmanifest. xml <uses-Permission Android: Name = "android. Permission. Vibrate"> </uses-Permission>

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: 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.