api 26 에서 부터 vibrator 가 deprecated 되었고 관련 항목으로 VibrationEffect class 가 추가됨을 확인
reference 문서는 https://developer.android.com/reference/android/os/VibrationEffect.html 이고
문서를 본 결과
one shot 일 경우
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibrator.vibrate(milliseconds);
}
repeat 가 필요한 경우
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
vibrator.vibrate(VibrationEffect.createWaveform(pattern, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibrator.vibrate(pattern, repeat);
}
식으로 사용하면 될듯
reference 문서는 https://developer.android.com/reference/android/os/VibrationEffect.html 이고
문서를 본 결과
one shot 일 경우
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibrator.vibrate(milliseconds);
}
repeat 가 필요한 경우
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
vibrator.vibrate(VibrationEffect.createWaveform(pattern, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibrator.vibrate(pattern, repeat);
}
식으로 사용하면 될듯
'Android' 카테고리의 다른 글
lint 에서 deprecated statement 할때 넣는 주석 (0) | 2017.10.10 |
---|---|
Unboxing of 'characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)' may produce 'java.lang.NullPointerException' (0) | 2017.10.10 |
unit test java.lang.RuntimeException: Method put in org.json.JSONObject not mocked (0) | 2017.09.25 |
rxjava2 (0) | 2017.09.14 |
logger hugo (0) | 2017.09.14 |