是否可以使用 IMPORTANCE_MIN 将前台服务通知放入通知通道?

Is it possible to put a foreground service notification in a notification channel with IMPORTANCE_MIN?

我目前正在努力将应用程序过渡到 Android O,并且我目前正在处理通知渠道。

我已经用不同的 importance levels 创建了不同的频道,并且由于应用程序有一个前台服务必须一直 运行 直到我们过渡到一个新的架构(更面向推送),我考虑过将该通知放在重要性设置为 IMPORTANCE_MIN 的频道中,这样它就在那里,但不会打扰用户,也不会在状态栏中放置图标。

但是,当我这样做并将我的应用程序置于后台(使用“主页”或“后退”按钮)时,我收到一条 Android 系统通知,告诉我我的应用程序正在 运行ning在后台,像这样:

如果我更改我的频道并使其使用 IMPORTANCE_LOW,问题就会消失,但通知会更加突出。

所以,我的问题是 - 是否有可能做我正在尝试的事情?我知道系统不允许开发人员这样做,因为如果你有前台服务,它应该对用户可见,但这只是一个猜测,我没有找到关于这个的文档,这就是为什么我发布这个问题。

我的第二个问题是 - 在 O 之前,如果您将通知的优先级设置为 PRIORITY_MIN,您是否可以将该通知绑定到服务以使其成为前台服务,或者是不是 -一直以来都去吗?

编辑:确认Android系统显示重要频道IMPORTANCE_MIN的通知(感谢M66B),所以现在剩下的问题也就是为什么?有谁知道这背后的原因,或者可以在任何地方找到任何文档?这可能是一个应该报告给跟踪器的错误吗?

此行为现已记录在案:https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_MIN

Min notification importance: only shows in the shade, below the fold. This should not be used with Service.startForeground since a foreground service is supposed to be something the user cares about so it does not make semantic sense to mark its notification as minimum importance. If you do this as of Android version O, the system will show a higher-priority notification about your app running in the background.

还有这里:https://material.io/guidelines/patterns/notifications.html#notifications-settings

In Android O, a channel’s default importance level for foreground service notifications must be at least IMPORTANCE_LOW so that it shows an icon in the status bar.

Channels using the less-prominent IMPORTANCE_MIN level will trigger an extra notification from Android at IMPORTANCE_LOW, stating that the app is using battery.

旁注: 这对我们来说是一个真正的痛苦,因为在 O 之前,当我们的前台通知没有要显示的有趣信息时,我们常常在 PRIORITY_DEFAULT 和 PRIORITY_MIN 之间动态切换。对于频道,我们无法再动态更改 IMPORTANCE,因此不得不删除该功能。