gpt4 book ai didi

Android O - 关闭通知 channel 然后打开,重要性级别始终重置为中等

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:12 24 4
gpt4 key购买 nike

在 Android O 中,我们可以有不同优先级(重要性)的不同通知 channel 。在我的代码中,我将 channel 重要性级别设置为紧急,即“发出声音并在屏幕上弹出”。

但是当我转到通知设置,关闭 channel 通知,然后再打开时,重要性级别将始终重置为中等(“无声音”),这是默认级别。

我知道我们总是可以手动更改重要性级别,但是有没有办法让它记住 channel 关闭前的设置,以便再次打开时,它会自动恢复到之前的设置?

最佳答案

Notifications 似乎没有记住你的重要程度的功能。在代码中保存 channel 的默认重要性并不难。

这是我的测试:

我在开始时创建了一个重要性级别为 IMPORTANCE_HIGH 的通知 channel 。然后从“设置”或长按通知弹出窗口关闭通知。重要性级别变为 IMPORTANCE_NONE。当我再次打开通知时,它变为 IMPORTANCE_LOW。

以下示例代码用于检查在您关闭和打开通知 channel 并将其设置为原始重要性后级别是否降低。

    NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = notificationManager.getNotificationChannel("your_channel_id");

int importance = notificationChannel.getImportance();
if (importance < NotificationManager.IMPORTANCE_HIGH && importance > 0 ) {
notificationChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
}

关于Android O - 关闭通知 channel 然后打开,重要性级别始终重置为中等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46185818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com