1.震动是系统的服务,首先需添加震动权限
<uses-permission android:name="android.permission.VIBRATE" />
2.实现震动方法代码
public static void sendVibrater(Context mContext) { // 间隔震动
Vibrator mVibrator = (Vibrator) mContext
.getSystemService(mContext.VIBRATOR_SERVICE);
long[] mPattern = { 200, 200, 200, 200, 200, 200 }; // 震动时间;间隔时间...手机常用的震动都是这样的
// mVibrator.vibrate(pattern, repeat);
mVibrator.vibrate(mPattern, 0);
}
public static void sendVibrate(Context mContext, long mLastTime) { //连续震动 mLastTime 时间
Vibrator mVibrator = (Vibrator) mContext
.getSystemService(mContext.VIBRATOR_SERVICE);
// mVibrator.vibrate(milliseconds);
mVibrator.vibrate(mLastTime);
}