本文介绍了NotificationChannel 名称和描述的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中设置通知时,从Oreo开始,还需要设置一个NotificationChannel

为了设置它,你需要给它一个 name: String 和一个 description: String 这是可选的.

val name = "测试通道"val description = "测试描述"val 重要性 = NotificationManager.IMPORTANCE_DEFAULTval channel = NotificationChannel("ID", 名称, 重要性)频道.描述 = 描述

根据文档,我无法弄清楚为什么您需要输入这两个值,它们不会出现在 UI 中,即使在新的 Android P 测试版中也不会显示.

创建 NotificationChannel 时使用的名称和描述是什么?

正如前两个答案所表明的那样,我在询问时可能不清楚.我知道 NotificationChannel 是干什么用的,我不清楚 name 和 description 属性是干什么用的.

解决方案

  • NotificationChannel 使我们的应用程序开发人员能够将我们的通知分组到组频道中,用户可以一次修改整个频道的通知设置
  • 通知渠道允许我们将通知分成不同的组/类别.每个通道都有一个共同的功能.它允许用户自定义他们的通知设置.

用户可以从应用设置中执行以下操作:

  1. 阻止来自特定频道的通知.

  2. 在不同的通知渠道上设置优先级/静音.

NotificationChannel 名称的用途

NotificationChannel 名称用于在系统设置中显示 NotificationChannel

setName() 用于设置一个 NotificationChannel 的名称setName() 设置 NotificationChannel 的用户可见名称.

推荐的最大长度为 40 个字符;如果太长,该值可能会被截断.

NotificationChannel 描述的目的

NotificationChannel 说明

设置 NotificationChannel 的用户可见描述.

指定用户在系统设置中看到的描述

When setting up notification in Android, starting from Oreo, you need to setup also a NotificationChannel

In order to set it up you need to give it a name: String and a description: String which is optional.

val name = "test channel"
val description = "test description"
val importance = NotificationManager.IMPORTANCE_DEFAULT

val channel = NotificationChannel("ID", name, importance)
channel.description = description

I couldn't figure out as per the documentation why you need to enter this two values, They don't seam to show up in the UI, not even in the new Android P betas.

What are name and description used for when creating a NotificationChannel?

EDIT:

As evinced by the first two answers, I probably wasn't clear when asking. I know what NotificationChannel is for, It's not clear to me what the name and description attributes are for.

解决方案

  • NotificationChannel enable us app developers to group our notifications into groups channels with the user having the ability to modify notification settings for the entire channel at once
  • Notification Channels allow us to separate notifications into different groups/categories. Every channel would have a common functionality. It allows the user to customize their notification settings.

Feature the user can do the following things from the Apps Settings:

  1. Block notifications from a particular channel.

  2. Set priority/silent on different notification channels.

the NotificationChannel name is use for displaying NotificationChannel in system setting

setName() is used to set the name of a NotificationChannel setName() Sets the user visible name of a NotificationChannel.

The recommended maximum length is 40 characters; the value may be truncated if it is too long.

NotificationChannel Description

Sets the user visible description of a NotificationChannel.

specify the description that the user sees in the system settings

这篇关于NotificationChannel 名称和描述的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 01:49