Dan*_*ele 3 android push-notification
在 Android 中设置通知时,从 Oreo 开始,您还需要设置一个 NotificationChannel
为了设置它,你需要给它一个name: String和一个description: String是可选的。
val name = "test channel"
val description = "test description"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("ID", name, importance)
channel.description = description
Run Code Online (Sandbox Code Playgroud)
根据文档,我无法弄清楚为什么需要输入这两个值,它们不会出现在 UI 中,即使在新的 Android P 测试版中也不会出现。
创建 NotificationChannel 时使用的名称和描述是什么?
编辑:
正如前两个答案所表明的那样,我在询问时可能不清楚。我知道是干什么NotificationChannel用的,我不清楚 name 和 description 属性是干什么用的。
NotificationChannel 的目的
NotificationChannel 使我们的应用程序开发人员能够将我们的通知分组到组频道中,用户可以一次修改整个频道的通知设置用户可以从应用程序设置中执行以下操作的功能:
阻止来自特定频道的通知。
在不同的通知渠道上设置优先级/静音。
NotificationChannel 名称的用途
NotificationChannel 名称用于在系统设置中显示 NotificationChannel
setName()用于设置 NotificationChannel 的名称setName()设置NotificationChannel
的用户可见名称。
建议的最大长度为 40 个字符;如果太长,该值可能会被截断。
NotificationChannel 描述的目的
NotificationChannel Description
设置用户可见的NotificationChannel.
指定用户在系统设置中看到的描述
| 归档时间: |
|
| 查看次数: |
3534 次 |
| 最近记录: |