From 41ffb013945104e01306645e538dc523f9daaed1 Mon Sep 17 00:00:00 2001 From: andfed Date: Sat, 23 Nov 2024 16:52:57 +0100 Subject: [PATCH] Fix vibration for SDK >= 33 --- .../messenger/voip/VoIPPreNotificationService.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPPreNotificationService.java b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPPreNotificationService.java index e92e5af4a..7d893b60b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPPreNotificationService.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPPreNotificationService.java @@ -18,6 +18,8 @@ import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; +import android.os.VibrationAttributes; +import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings; import android.text.SpannableString; @@ -357,7 +359,16 @@ public class VoIPPreNotificationService { // } extends Service implements AudioM } else if (vibrate == 3) { duration *= 2; } - vibrator.vibrate(new long[]{0, duration, 500}, 0); + long[] pattern = new long[]{0, duration, 500}; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + vibrator.vibrate( + VibrationEffect.createWaveform(pattern, 0), + new VibrationAttributes.Builder() + .setUsage(VibrationAttributes.USAGE_RINGTONE) // required for background apps + .build()); + } else { + vibrator.vibrate(pattern, 0); + } } } }