Skip to content

Commit

Permalink
Avoid deprecated APIs for vibration
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Miś <[email protected]>
  • Loading branch information
PatrykMis committed May 7, 2024
1 parent 3e63095 commit 18b9b00
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package com.neo.speaktouch.di.module

import android.content.Context
import android.media.AudioAttributes
import android.os.Build
import android.os.Vibrator
import android.os.VibratorManager
import android.speech.tts.TextToSpeech
import com.neo.speaktouch.R
import com.neo.speaktouch.controller.Controllers
Expand All @@ -44,7 +46,14 @@ object ControllerModule {
context: Context
) : VibratorController {

val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val vibratorManager =
context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
vibratorManager.defaultVibrator
} else {
@Suppress("DEPRECATION")
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
}

return VibratorController(vibrator)
}
Expand Down

0 comments on commit 18b9b00

Please sign in to comment.