vibration android studio

Solutions on MaxInterview for vibration android studio by the best coders in the world

showing results for - "vibration android studio"
Ryad
23 Mar 2019
1import android.os.Vibrator;
2...
3// Pause for 500ms, vibrate for 500ms, then start again
4private static final long[] VIBRATE_PATTERN = { 500, 500 };
5
6mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
7
8if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
9    // API 26 and above
10    mVibrator.vibrate(VibrationEffect.createWaveform(VIBRATE_PATTERN, 0));
11} else {
12    // Below API 26
13    mVibrator.vibrate(VIBRATE_PATTERN, 0);
14}
15
Alycia
20 Oct 2020
1// Get instance of Vibrator from current Context
2Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
3
4// Start without a delay
5// Each element then alternates between vibrate, sleep, vibrate, sleep...
6long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};
7
8// The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array
9v.vibrate(pattern, -1);
10
Cristina
10 Aug 2019
1// Get instance of Vibrator from current Context
2Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
3
4// Start without a delay
5// Vibrate for 100 milliseconds
6// Sleep for 1000 milliseconds
7long[] pattern = {0, 100, 1000};
8
9// The '0' here means to repeat indefinitely
10// '0' is actually the index at which the pattern keeps repeating from (the start)
11// To repeat the pattern from any other point, you could increase the index, e.g. '1'
12v.vibrate(pattern, 0);
13