You've already forked ChameleonBLEAPI
mirror of
https://github.com/RfidResearchGroup/ChameleonBLEAPI.git
synced 2026-05-12 11:20:47 -07:00
28 lines
892 B
Java
28 lines
892 B
Java
|
|
package com.proxgrind.chameleon.utils.system;
|
||
|
|
|
||
|
|
import android.content.Context;
|
||
|
|
import android.os.VibrationEffect;
|
||
|
|
import android.os.Vibrator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 震动工具!
|
||
|
|
*
|
||
|
|
* @author DXL
|
||
|
|
*/
|
||
|
|
public class VibratorUtils {
|
||
|
|
|
||
|
|
//进行抖动!
|
||
|
|
public static void runOneAsDelay(Context context, int delay) {
|
||
|
|
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||
|
|
if (vibrator != null)
|
||
|
|
if (vibrator.hasVibrator()) { //有振动器
|
||
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||
|
|
VibrationEffect vibrationEffect = VibrationEffect.createOneShot(delay, VibrationEffect.DEFAULT_AMPLITUDE);
|
||
|
|
vibrator.vibrate(vibrationEffect);
|
||
|
|
} else {
|
||
|
|
vibrator.vibrate(delay);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|