Android: How do I repeat a notification sound until the notification is opened?

1.3k Views Asked by At

I am currently working on an Android App, that needs to alarm the user in case of an emergency. When the app needs to alert, it notifies the user with a heads-up notification and plays a loud sound. My problem is that I can't get the sound to repeat itself after it ends. I basically want it to loop until the users opens the notification.

I've tried to use Notification.FLAG_INSISTENT in both notification.flags and audioAttributes.setFlags(...) (inside of notificationChannel.setSound(audio, audioAttributes)), however this doesn't work.

Thanks ^^

1

There are 1 best solutions below

0
thaovd1712 On

I check in DeskClock app in AOSP, they set sound of notification to null then use MediaPlayer to play sound.

channel.setSound(null, null)

https://cs.android.com/android/platform/superproject/main/+/main:packages/apps/DeskClock/src/com/android/deskclock/NotificationUtils.kt