使用Vibrator的vibrate()可调节震动时间;cancel()取消震动。

<!—震动权限-->

<uses-permission android:name="android.permission.VIBRATE"/>

//振动器实例化

private Vibrator mVibrator1;

mVibrator1=(Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);


//等待100ms后,按数组所给数值间隔震动;其后为重复次数,-1为不重复,0一直震动

mVibrator1.vibrate(new long[]{100,10,100,1000}, -1);


//震动指定时间

mVibrator1.vibrate(2000);


//取消震动

mVibrator1.cancel();