2

On Android, when creating a channel, there are two properties: setBypassDnd and setLockscreenVisibility, that are only modifiable by the system (https://developer.android.com/reference/android/app/NotificationChannel). I have tested creating a channel with those values:

    if (Build.VERSION.SDK_INT >= 26) {

        //we give it a name, description and importance
        CharSequence name = context.getString(R.string.channel_name);
        String channelID = getNotificationChannelID(getSharedPreferences(context));
        NotificationChannel channel = new NotificationChannel(channelID, name, importance);

        channel.setBypassDnd(true);
        channel.setLockscreenVisibility(VISIBILITY_SECRET);

        // Register the channel with the system
        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }

But the values in the channel are set as per default (bypassDnd=false and LockscreenVisibility=VISIBILITY_PUBLIC) which I understand is caused by the "only modifiable by system" restriction.

I am recreating the channel as this seems to be the only way to change vibration/sound/LED after the channel is created, but I want to keep all the properties the user might have set.

I guess at this point this is a limitation I cannot overcome, but I am curious if anyone has found a way to work around this or this is just how it is.

nichtwer
  • 61
  • 1
  • 6
  • Same to me. Did you find any solution to this? – chrisonline Feb 22 '21 at 13:44
  • I'm afraid this seems to be a limitation. The lesson here is not to recreate channels and let user make any changes. If the option is very important to you, you can always take user to the notification settings for them to make the change, but that's it. – nichtwer Feb 23 '21 at 14:11
  • Yes of course, but the problem is that some settings are not changeable by the user in the system settings. For example: Vibration Pattern can only be added via Code, but is not changeable via system settings. And on some phone manufacturers there are no way to change this in the system settings. – chrisonline Feb 24 '21 at 16:03

0 Answers0