r/flutterhelp • u/nation198 • 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
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.