setBypassDnd和setLockscreenVisibility仅可由系统修改

问题描述

在Android上,创建频道时,有两个属性:setBypassDnd和setLockscreenVisibility,它们只能由系统(https://developer.android.com/reference/android/app/NotificationChannel修改。 我已经测试过使用这些值创建频道:

    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);
    }
@H_404_5@

但是通道中的值是认设置的(bypassDnd = false和LockscreenVisibility = VISIBILITY_PUBLIC),据我所知是由“只能由系统修改”限制引起的。

我正在重新创建通道,因为这似乎是创建通道后更改振动/声音/ LED的唯一方法,但是我想保留用户可能已设置的所有属性

我想这是我无法克服的局限性,但是我很好奇是否有人找到了解决此问题的方法,或者这就是事实。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)