似乎沒有通知功能來記住您的重要性級別。在您的代碼中保存頻道的默認重要性並不難。
這是我的測試:
我創建了重要性水平IMPORTANCE_HIGH在開始時通知通道。然後通過設置或長按通知彈出來關閉通知。重要性級別變爲IMPORTANCE_NONE。當我再次打開通知時,它變爲IMPORTANCE_LOW。
以下是示例代碼,用於檢查在關閉並打開通知通道後級別是否已降低並將其設置爲原始重要性。
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);
}