Code first
Package COM. test; import android. app. activity; import android. app. service; import android. OS. bundle; import android. OS. vibrator; import android. view. view; import android. view. view. onlongclicklistener; import android. widget. textview; public class againtestactivity extends activity implements onlongclicklistener {private textview news;/** called when the activity is first created. * // @ override public void on Create (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); findviews (); setlistner ();} private void setlistner () {NEWS. setonlongclicklistener (this);} private void findviews () {NEWS = (textview) findviewbyid (R. id. newsword) ;}@ overridepublic Boolean onlongclick (view v) {Switch (v. GETID () {case R. id. newsword:/** vibration Service */vibrator VIB = (vibrator) This. getsystemser Vice (service. vibrator_service); // vibrator. vibrate (1000); // only vibrate for one second, one long [] pattern = {}; // two parameters, one is custom vibration mode, // The meanings of numbers in the array are static duration, vibration duration, static duration, and vibration duration... The unit of duration is millisecond // The second parameter is "whether to vibrate repeatedly".-1 does not vibrate repeatedly // The second parameter must be smaller than the pattern length. Otherwise, arrayindexoutofboundsexceptionvib will be thrown. vibrate (pattern, 1); break; default: break;} return false ;}}
Of course, in the registration file, add <uses-Permission Android: Name = "android. Permission. Vibrate"/>