Fix vibration for SDK >= 33

This commit is contained in:
andfed 2024-11-23 16:52:57 +01:00
parent fb2e545101
commit 41ffb01394

View file

@ -18,6 +18,8 @@ import android.media.MediaPlayer;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import android.text.SpannableString; import android.text.SpannableString;
@ -357,7 +359,16 @@ public class VoIPPreNotificationService { // } extends Service implements AudioM
} else if (vibrate == 3) { } else if (vibrate == 3) {
duration *= 2; 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);
}
} }
} }
} }