【发布时间】:2019-01-02 17:50:42
【问题描述】:
不久前,我更新了我的应用程序以添加对 Android 8+ 的支持,在更新通知以使用所需的 NotificationChannel 后,我注意到我失去了一项功能。 该应用程序使用计时器通知,当时我能够更新通知优先级,使用 PRIORITY_HIGH 显示通知,因此通知被“推送”给用户,然后将通知优先级编辑为PRIORITY_LOW,隐藏通知。
阅读文档后,据我所知,创建 NotificationChannel 后我无法控制优先级,将此控制权留给用户,但是,要求用户编辑通知设置对我的使用而言并不是最佳选择.
相关代码:
//Creating the notification channel (while setting up the app)
NotificationChannel channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_HIGH);
//Editing the NotificationChannel to lower the Notification priority (not working)
NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
channel.setImportance(NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
有没有办法完成这种行为,同时仍然使用 NotificationChannels?
【问题讨论】:
-
也许您可以有两个具有不同优先级/重要性的通知渠道?
-
@JoeyDalu 是的,我想过,但是为此设置一个频道似乎有点奇怪,但是,如果这是唯一的选择,我可能不得不......哈哈
标签: android notifications notification-channel