flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

[Feature] Add setBypassDnd option to Android Notificationchannel creation

Open KaiBroeker opened this issue 3 years ago • 4 comments

Hello, I like flutter_local_notifications much, but there is one feature I need and is missing. The feature I need is the option to set "setBypassDnd" by creating a Android Notificaitonchannel.

If I create a notification channel in java, I can set the option and after allowing this feature in notificaiton settings of Android, Notifications of this channel are also loud if dnd is on.

example code:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationManager notificationManager = getSystemService(NotificationManager.class);

            String CHANNEL_ID = "alarm";
            CharSequence name = "alarm";
            String description = "alarm";

            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, name, importance);
            notificationChannel.setDescription(description);

            notificationChannel.setBypassDnd(true);

            if (notificationManager != null) {
                notificationManager.createNotificationChannel(notificationChannel);
            }
        }

Through adding this feature I don't need duplicate code anymode.

Thank you, for your good work :)

KaiBroeker avatar Jun 28 '21 15:06 KaiBroeker

How about submitting a PR given you have some Android code there as well? :)

MaikuB avatar Jun 29 '21 22:06 MaikuB

I have made that change directly in a fork of this plugin to check if it works: https://github.com/adrianlzt/flutter_local_notifications/commit/3b8b20c945fc73317a2f76d3b9d710f2dd0481bd

But it doesn't work. The notification makes no sound.

Could also be that mi phone is a Xiaomi using MIUI. It does not have the option to allow apps to skip DND.

adrianlzt avatar Oct 28 '21 16:10 adrianlzt

If you don't have access to a stock Android device then I would suggest looking at using an emulator. Note that I do have a Pixel 4 XL so I can use that to test a PR should one be submitted

MaikuB avatar Oct 29 '21 13:10 MaikuB

I need the app to run in my phone. I have finally disabled DND before running the notification.

adrianlzt avatar Oct 29 '21 17:10 adrianlzt