需要添加权限
<uses-permission android:name="android.permission.VIBRATE" />
public void setVibrator(){
String vibratorService = Context.VIBRATOR_SERVICE;
Vibrator vibrator = (Vibrator)getSystemService(vibratorService);
//定义振动模式: {暂停时间,振动时间,暂停时间,振动时间,...}
long[] pattern = {1000, 2000, 3000, 4000, 5000, 6000};
vibrator.vibrate(pattern, -1);//使用振动方式(-1: 代表不重复)
//vibrator.vibrate(1000);//振动1秒钟
//取消振动(退出程序会自动停止任何已经初始化的振动)
//vibrator.cancel();
}