Android achieves vibration. See the following code.
Layout file main. xml
- <? XMLVersion = "1.0" encoding = "UTF-8"?>
- <LinearlayoutXmlns: Android = "http://schemas.android.com/apk/res/android"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Orientation = "vertical">
- <Textview
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- Android: text = "@ string/hello"/>
- <Button
- Android: Id = "@ + ID/BTN"
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- Android: text = "vibration test"/>
- </Linearlayout>
Activity File
- PackageCom. suxh. activity;
- ImportAndroid. App. activity;
- ImportAndroid. App. Service;
- ImportAndroid. content. PM. activityinfo;
- ImportAndroid. OS. Bundle;
- ImportAndroid. OS. vibrator;
- ImportAndroid. View. view;
- ImportAndroid. View. View. onclicklistener;
- ImportAndroid. View. window;
- ImportAndroid. View. windowmanager;
- ImportAndroid. widget. Button;
- Public ClassActivity1ExtendsActivity {
- PrivateButton BTN;
- PrivateVibrator mvibrator01; // declare a vibrator object
- @ Override
- Public VoidOncreate (bundle savedinstancestate ){
- Super. Oncreate (savedinstancestate );
- // Set it to no title bar
- Requestwindowfeature (window. feature_no_title );
- // Set to full screen mode
- Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen );
- // Set to landscape
- Setrequestedorientation (activityinfo. screen_orientation_landscape );
- Setcontentview (R. layout. Main );
- BTN = (button) findviewbyid (R. Id. BTN );
- BTN. setonclicklistener (NewOnclicklistener (){
- @ Override
- Public VoidOnclick (view v ){
- Mvibrator01 = (vibrator) getapplication (). getsystemservice (service. vibrator_service );
- Mvibrator01.vibrate (New Long[] {100,10, 100,1000},-1 );
- }
- });
- }
- }