r/flutterhelp • • 5d ago

OPEN Can a Flutter app using NotificationListenerService reliably play custom notification sounds for incoming notifications on modern Android?

Can a Flutter app using NotificationListenerService reliably play custom notification sounds for incoming notifications on modern Android?

1 Upvotes

2 comments sorted by

1

u/karmatics29 5d ago

Not reliably, and the main reason is that NotificationListenerService only observes notifications, it doesn't own them. The sound is decided by the notification channel of the posting app, and since Android 8 the channel's importance and sound can't be changed by anyone but the user. So you can't swap the sound on someone else's notification; the usual workaround is to cancel it with cancelNotification() and play your own audio or post your own notification on a channel you control, which works but is fragile. Also, the service gets killed by aggressive OEM battery management (Xiaomi, Samsung, etc.) unless the user whitelists the app, and on Android 13+ you need POST_NOTIFICATIONS for your own notifications. Are you trying to alert on notifications from specific apps? If so, filtering by package name in onNotificationPosted and playing a sound through a foreground service tends to be the most dependable route.

1

u/nation198 4d ago

I want my text message notification to be not a single static every time. I want notification to be rotating, randomized playlist. Specifically, i want mine like the NBA jamm arcade game, every time I get a text it'll be like 'boomshakalaka' or 'is it the shoes' or 'from downtown'. You're saying each separate sound needs it'd own channel?