There are tutorials for this on the internet but the code is in Java and I'm new to Kotlin so I am not able to figure out how I can do the same in Kotlin.
The code I tried in Kotlin.
var pattern = longArrayOf(0, 200, 500)
val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
vibrator.vibrate(pattern, 5)
Edit 2: I created a function
@RequiresApi(Build.VERSION_CODES.O)
private fun vibrate(context: Context){
var pattern = longArrayOf(0, 200, 500)
val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
vibrator.vibrate(VibrationEffect.createWaveform(pattern,5))
}
and i called it in the onFinish function of CountDownTimer
@RequiresApi(Build.VERSION_CODES.O)
override fun onFinish() {
vibrate(this@MeditateActivity)
}
i tried running the app on my android device but my device didn't vibrate at all