Skip to content

Instantly share code, notes, and snippets.

@nieldeokar
Last active November 13, 2017 11:33
Show Gist options
  • Save nieldeokar/2ea4ff56fa9b6310c3288b8b4c4d184c to your computer and use it in GitHub Desktop.
Save nieldeokar/2ea4ff56fa9b6310c3288b8b4c4d184c to your computer and use it in GitHub Desktop.
This method would create wave form vibration using vibration effect
@RequiresApi(api = Build.VERSION_CODES.O)
private void createWaveFormVibrationUsingVibrationEffectAndAmplitude() {
long[] mVibratePattern = new long[]{0, 400, 800, 600, 800, 800, 800, 1000};
int[] mAmplitudes = new int[]{0, 255, 0, 255, 0, 255, 0, 255};
// -1 : Play exactly once
if (vibrator.hasAmplitudeControl()) {
VibrationEffect effect = VibrationEffect.createWaveform(mVibratePattern, mAmplitudes, -1);
vibrator.vibrate(effect);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment