Android Phone Shake

Source: Internet
Author: User

Vibrator is an Android-supplied vibrator that does not have a constructor to get objects through the Getsystemservice (Context.vibrator_service) method. However, when using this class, you need to add access permissions to the manifest file Android.permission.VIBRATE. In actual use can set the vibration period has been accessed time

Package Com.basillee.asus.demo;import Android.content.context;import android.os.vibrator;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.widget.Button; Public classMainActivity10 extends Actionbaractivity {Button Shortbutton=NULL; Button Longbutton=NULL; Button Stopbutton=NULL; Vibrator Vibrator=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY10); Shortbutton=(Button) Findviewbyid (r.id.short_vibrate); Longbutton=(Button) Findviewbyid (r.id.long_vibrate); Stopbutton=(Button) Findviewbyid (r.id.stop_vibrate); Vibrator=(Vibrator) Getsystemservice (Context.vibrator_service); Shortbutton.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {vibrator.vibrate (New Long[]{ -, -},0);        }        }); Longbutton.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {vibrator.vibrate (New Long[]{ +, the, +, the},-1);        }        }); Stopbutton.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {vibrator.cancel ();    }        }); }}


Android Phone Shake

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.