上方法
Vibrator mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
long[] patern = {0,1000,1000};
AudioAttributes audioAttributes = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION) //key
.build();
//-1 一次震动 else 重复
mVibrator.vibrate(pattern, -1, audioAttributes);
}else {
mVibrator.vibrate(pattern, -1);
}
网友评论