Added in API level 26

NotificationChannel


class NotificationChannel : Parcelable
kotlin.Any
   ↳ android.app.NotificationChannel

A representation of settings that apply to a collection of similarly themed notifications.

Summary

Constants
static String

The id of the default channel for an app.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

static String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST.

Inherited constants
Public constructors
NotificationChannel(id: String!, name: CharSequence!, importance: Int)

Creates a notification channel.

Public methods
Boolean

Returns whether notifications posted to this channel are allowed to display outside of the notification shade, in a floating window on top of other apps.

Boolean

Whether or not notifications posted to this channel can bypass the Do Not Disturb NotificationManager#INTERRUPTION_FILTER_PRIORITY mode when the active policy allows priority channels to bypass notification filtering.

Boolean

Returns whether notifications posted to this channel can appear as badges in a Launcher application.

Int

Unit

Sets whether notifications posted to this channel should display notification lights, on devices that support that feature.

Unit

Sets whether notification posted to this channel should vibrate.

Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

AudioAttributes!

Returns the audio attributes for sound played by notifications posted to this channel.

String?

Returns the id of the conversation backing this channel, if it's associated with a conversation.

String!

Returns the user visible description of this channel.

String!

Returns what group this channel belongs to.

String!

Returns the id of this channel.

Int

Returns the user specified importance e.

Int

Returns the notification light color for notifications posted to this channel.

Int

Returns whether or not notifications posted to this channel are shown on the lockscreen in full or redacted form.

CharSequence!

Returns the user visible name of this channel.

String?

Returns the id of the parent notification channel to this channel, if it's a conversation related channel.

Uri!

Returns the notification sound for this channel.

VibrationEffect?

Returns the VibrationEffect for notifications posted to this channel.

LongArray!

Returns the vibration pattern for notifications posted to this channel.

Boolean

Returns whether the user has chosen the importance of this channel, either to affirm the initial selection from the app, or changed it to be higher or lower.

Boolean

Returns whether the user has chosen the sound of this channel.

Int

Boolean

Returns whether this channel is always blockable, even if the app is 'fixed' as non-blockable.

Boolean

Whether or not this channel represents a conversation.

Boolean

Returns whether the user has decided that this channel does not represent a conversation.

Boolean

Whether or not notifications in this conversation are considered important.

Unit
setAllowBubbles(allowBubbles: Boolean)

As of Android 11 this value is no longer respected.

Unit
setBlockable(blockable: Boolean)

Allows users to block notifications sent through this channel, if this channel belongs to a package that otherwise would have notifications "fixed" as enabled.

Unit
setBypassDnd(bypassDnd: Boolean)

Sets whether or not notifications posted to this channel can interrupt the user in android.app.NotificationManager.Policy#INTERRUPTION_FILTER_PRIORITY mode.

Unit
setConversationId(parentChannelId: String, conversationId: String)

Sets this channel as being converastion-centric.

Unit
setDescription(description: String!)

Sets the user visible description of this channel.

Unit
setGroup(groupId: String!)

Sets what group this channel belongs to.

Unit
setImportance(importance: Int)

Sets the level of interruption of this notification channel.

Unit

Sets the notification light color for notifications posted to this channel, if lights are enabled on this channel and the device supports that feature.

Unit
setLockscreenVisibility(lockscreenVisibility: Int)

Sets whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form.

Unit

Sets the user visible name of this channel.

Unit
setShowBadge(showBadge: Boolean)

Sets whether notifications posted to this channel can appear as application icon badges in a Launcher.

Unit
setSound(sound: Uri!, audioAttributes: AudioAttributes!)

Sets the sound that should be played for notifications posted to this channel and its audio attributes.

Unit

Sets a VibrationEffect for notifications posted to this channel.

Unit
setVibrationPattern(vibrationPattern: LongArray!)

Sets the vibration pattern for notifications posted to this channel.

Boolean

Returns whether notifications posted to this channel trigger notification lights.

Boolean

Returns whether notifications posted to this channel always vibrate.

String

Unit
writeToParcel(dest: Parcel, flags: Int)

Properties
static Parcelable.Creator<NotificationChannel!>

Constants

DEFAULT_CHANNEL_ID

Added in API level 26
static val DEFAULT_CHANNEL_ID: String

The id of the default channel for an app. This id is reserved by the system. All notifications posted from apps targeting android.os.Build.VERSION_CODES#N_MR1 or earlier without a notification channel specified are posted to this channel.

Value: "miscellaneous"

EDIT_CONVERSATION

Added in API level 31
static val EDIT_CONVERSATION: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing conversation settings (demoting or restoring a channel to be a Conversation, changing bubble behavior, or setting the priority of a conversation).

Value: "conversation"

EDIT_IMPORTANCE

Added in API level 31
static val EDIT_IMPORTANCE: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing importance (setImportance(int)) and/or conversation priority.

Value: "importance"

EDIT_LAUNCHER

Added in API level 31
static val EDIT_LAUNCHER: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing launcher behavior (showing badges)}.

Value: "launcher"

EDIT_LOCKED_DEVICE

Added in API level 31
static val EDIT_LOCKED_DEVICE: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing behavior on devices that are locked or have a turned off display (setLockscreenVisibility(int), enableLights(boolean), setLightColor(int)).

Value: "locked"

EDIT_SOUND

Added in API level 31
static val EDIT_SOUND: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing sound, like a tone picker (setSound(android.net.Uri,android.media.AudioAttributes)).

Value: "sound"

EDIT_VIBRATION

Added in API level 31
static val EDIT_VIBRATION: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing vibration (enableVibration(boolean), setVibrationPattern(long[])).

Value: "vibration"

EDIT_ZEN

Added in API level 31
static val EDIT_ZEN: String

Extra value for Settings#EXTRA_CHANNEL_FILTER_LIST. Include to show fields that have to do with editing do not disturb bypass {(@link #setBypassDnd(boolean)}) .

Value: "zen"

Public constructors

NotificationChannel

Added in API level 26
NotificationChannel(
    id: String!,
    name: CharSequence!,
    importance: Int)

Creates a notification channel.

Parameters
id String!: The id of the channel. Must be unique per package. The value may be truncated if it is too long.
name CharSequence!: The user visible name of the channel. You can rename this channel when the system locale changes by listening for the Intent#ACTION_LOCALE_CHANGED broadcast. The recommended maximum length is 40 characters; the value may be truncated if it is too long.
importance Int: The importance of the channel. This controls how interruptive notifications posted to this channel are. Value is android.app.NotificationManager#IMPORTANCE_UNSPECIFIED, android.app.NotificationManager#IMPORTANCE_NONE, android.app.NotificationManager#IMPORTANCE_MIN, android.app.NotificationManager#IMPORTANCE_LOW, android.app.NotificationManager#IMPORTANCE_DEFAULT, or android.app.NotificationManager#IMPORTANCE_HIGH

Public methods

canBubble

Added in API level 29
fun canBubble(): Boolean

Returns whether notifications posted to this channel are allowed to display outside of the notification shade, in a floating window on top of other apps.

canBypassDnd

Added in API level 26
fun canBypassDnd(): Boolean

Whether or not notifications posted to this channel can bypass the Do Not Disturb NotificationManager#INTERRUPTION_FILTER_PRIORITY mode when the active policy allows priority channels to bypass notification filtering.

canShowBadge

Added in API level 26
fun canShowBadge(): Boolean

Returns whether notifications posted to this channel can appear as badges in a Launcher application. Note that badging may be disabled for other reasons.

describeContents

Added in API level 26
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

enableLights

Added in API level 26
fun enableLights(lights: Boolean): Unit

Sets whether notifications posted to this channel should display notification lights, on devices that support that feature. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

enableVibration

Added in API level 26
fun enableVibration(vibration: Boolean): Unit

Sets whether notification posted to this channel should vibrate. The vibration pattern can be set with setVibrationPattern(long[]). Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

equals

Added in API level 26
fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
o This value may be null.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getAudioAttributes

Added in API level 26
fun getAudioAttributes(): AudioAttributes!

Returns the audio attributes for sound played by notifications posted to this channel.

getConversationId

Added in API level 30
fun getConversationId(): String?

Returns the id of the conversation backing this channel, if it's associated with a conversation. See setConversationId(java.lang.String,java.lang.String).

Return
String? This value may be null.

getDescription

Added in API level 26
fun getDescription(): String!

Returns the user visible description of this channel.

getGroup

Added in API level 26
fun getGroup(): String!

Returns what group this channel belongs to. This is used only for visually grouping channels in the UI.

getId

Added in API level 26
fun getId(): String!

Returns the id of this channel.

getImportance

Added in API level 26
fun getImportance(): Int

Returns the user specified importance e.g. NotificationManager#IMPORTANCE_LOW for notifications posted to this channel. Note: This value might be > NotificationManager#IMPORTANCE_NONE, but notifications posted to this channel will not be shown to the user if the parent NotificationChannelGroup or app is blocked. See NotificationChannelGroup#isBlocked() and NotificationManager#areNotificationsEnabled().

getLightColor

Added in API level 26
fun getLightColor(): Int

Returns the notification light color for notifications posted to this channel. Irrelevant unless shouldShowLights().

getLockscreenVisibility

Added in API level 26
fun getLockscreenVisibility(): Int

Returns whether or not notifications posted to this channel are shown on the lockscreen in full or redacted form.

getName

Added in API level 26
fun getName(): CharSequence!

Returns the user visible name of this channel.

getParentChannelId

Added in API level 30
fun getParentChannelId(): String?

Returns the id of the parent notification channel to this channel, if it's a conversation related channel. See setConversationId(java.lang.String,java.lang.String).

Return
String? This value may be null.

getSound

Added in API level 26
fun getSound(): Uri!

Returns the notification sound for this channel.

getVibrationEffect

Added in API level 35
fun getVibrationEffect(): VibrationEffect?

Returns the VibrationEffect for notifications posted to this channel. The returned effect is derived from either the effect provided in the setVibrationEffect(android.os.VibrationEffect) method, or the equivalent vibration effect of the pattern set via the setVibrationPattern(long[]) method, based on setter method that was called last. The returned effect will be ignored in one of the following cases:

  • vibration is not enabled for the channel (i.e. shouldVibrate() returns false).
  • the effect is not supported/playable by the device. In this case, if vibration is enabled for the channel, the default channel vibration will be used instead.

Return
VibrationEffect? the VibrationEffect set via setVibrationEffect(android.os.VibrationEffect), or the equivalent of the vibration set via setVibrationPattern(long[]). This value may be null.

getVibrationPattern

Added in API level 26
fun getVibrationPattern(): LongArray!

Returns the vibration pattern for notifications posted to this channel. Will be ignored if vibration is not enabled (shouldVibrate()).

hasUserSetImportance

Added in API level 29
fun hasUserSetImportance(): Boolean

Returns whether the user has chosen the importance of this channel, either to affirm the initial selection from the app, or changed it to be higher or lower.

See Also

hasUserSetSound

Added in API level 30
fun hasUserSetSound(): Boolean

Returns whether the user has chosen the sound of this channel.

See Also

hashCode

Added in API level 26
fun hashCode(): Int
Return
Int a hash code value for this object.

isBlockable

Added in API level 33
fun isBlockable(): Boolean

Returns whether this channel is always blockable, even if the app is 'fixed' as non-blockable.

isConversation

Added in API level 31
fun isConversation(): Boolean

Whether or not this channel represents a conversation.

isDemoted

Added in API level 31
fun isDemoted(): Boolean

Returns whether the user has decided that this channel does not represent a conversation. The value will always be false for channels that never claimed to be conversations - that is, for channels where getConversationId() and getParentChannelId() are empty.

isImportantConversation

Added in API level 30
fun isImportantConversation(): Boolean

Whether or not notifications in this conversation are considered important.

Important conversations may get special visual treatment, and might be able to bypass DND.

This is only valid for channels that represent conversations, that is, where isConversation() is true.

setAllowBubbles

Added in API level 29
fun setAllowBubbles(allowBubbles: Boolean): Unit

As of Android 11 this value is no longer respected.

setBlockable

Added in API level 33
fun setBlockable(blockable: Boolean): Unit

Allows users to block notifications sent through this channel, if this channel belongs to a package that otherwise would have notifications "fixed" as enabled. If the channel does not belong to a package that has a fixed notification permission, this method does nothing, since such channels are blockable by default and cannot be set to be unblockable.

Parameters
blockable Boolean: if true, allows users to block notifications on this channel.

setBypassDnd

Added in API level 26
fun setBypassDnd(bypassDnd: Boolean): Unit

Sets whether or not notifications posted to this channel can interrupt the user in android.app.NotificationManager.Policy#INTERRUPTION_FILTER_PRIORITY mode. Only modifiable by the system and notification ranker.

setConversationId

Added in API level 30
fun setConversationId(
    parentChannelId: String,
    conversationId: String
): Unit

Sets this channel as being converastion-centric. Different settings and functionality may be exposed for conversation-centric channels.

Parameters
parentChannelId String: The getId() id} of the generic channel that notifications of this type would be posted to in absence of a specific conversation id. For example, if this channel represents 'Messages from Person A', the parent channel would be 'Messages.' This value cannot be null.
conversationId String: The ShortcutInfo#getId() of the shortcut representing this channel's conversation. This value cannot be null.

setDescription

Added in API level 26
fun setDescription(description: String!): Unit

Sets the user visible description of this channel.

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

setGroup

Added in API level 26
fun setGroup(groupId: String!): Unit

Sets what group this channel belongs to. Group information is only used for presentation, not for behavior. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel), unless the channel is not currently part of a group.

Parameters
groupId String!: the id of a group created by NotificationManager#createNotificationChannelGroup(NotificationChannelGroup).

setImportance

Added in API level 26
fun setImportance(importance: Int): Unit

Sets the level of interruption of this notification channel. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

Parameters
importance Int: the amount the user should be interrupted by notifications from this channel. Value is android.app.NotificationManager#IMPORTANCE_UNSPECIFIED, android.app.NotificationManager#IMPORTANCE_NONE, android.app.NotificationManager#IMPORTANCE_MIN, android.app.NotificationManager#IMPORTANCE_LOW, android.app.NotificationManager#IMPORTANCE_DEFAULT, or android.app.NotificationManager#IMPORTANCE_HIGH

setLightColor

Added in API level 26
fun setLightColor(argb: Int): Unit

Sets the notification light color for notifications posted to this channel, if lights are enabled on this channel and the device supports that feature. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

setLockscreenVisibility

Added in API level 26
fun setLockscreenVisibility(lockscreenVisibility: Int): Unit

Sets whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form. See e.g. Notification#VISIBILITY_SECRET. Only modifiable by the system and notification ranker.

setName

Added in API level 26
fun setName(name: CharSequence!): Unit

Sets the user visible name of this channel.

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

setShowBadge

Added in API level 26
fun setShowBadge(showBadge: Boolean): Unit

Sets whether notifications posted to this channel can appear as application icon badges in a Launcher. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

Parameters
showBadge Boolean: true if badges should be allowed to be shown.

setSound

Added in API level 26
fun setSound(
    sound: Uri!,
    audioAttributes: AudioAttributes!
): Unit

Sets the sound that should be played for notifications posted to this channel and its audio attributes. Notification channels with an importance of at least NotificationManager#IMPORTANCE_DEFAULT should have a sound. Note: An app-specific sound can be provided in the Uri parameter, but because channels are persistent for the duration of the app install, and are backed up and restored, the Uri should be stable. For this reason it is not recommended to use a ContentResolver#SCHEME_ANDROID_RESOURCE uri, as resource ids can change on app upgrade. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

setVibrationEffect

Added in API level 35
fun setVibrationEffect(effect: VibrationEffect?): Unit

Sets a VibrationEffect for notifications posted to this channel. If the provided effect is non-null, will enable vibration on this channel (equivalent to calling enableVibration(boolean) with true). Otherwise vibration will be disabled unless enableVibration(boolean) is used with true, in which case the default vibration will be used.

The effect passed here will be returned from getVibrationEffect(). If the provided VibrationEffect is an equivalent to a wave-form vibration pattern, the equivalent wave-form pattern will be returned from getVibrationPattern().

Note that some VibrationEffects may not be playable on some devices. In cases where such an effect is passed here, vibration will still be enabled for the channel, but the default vibration will be used. Nonetheless, the provided effect will be stored and be returned from getVibrationEffect calls, and could be used by the same channel on a different device, for example, in cases the user backs up and restores to a device that does have the ability to play the effect, where that effect will be used instead of the default. To avoid such issues that could make the vibration behavior of your notification channel differ among different devices, it's recommended that you avoid vibration effect primitives, as the support for them differs widely among devices (read VibrationEffect.Composition for more on vibration primitives).

Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

Parameters
effect VibrationEffect?: This value may be null.

setVibrationPattern

Added in API level 26
fun setVibrationPattern(vibrationPattern: LongArray!): Unit

Sets the vibration pattern for notifications posted to this channel. If the provided pattern is valid (non-null, non-empty with at least 1 non-zero value), will enable vibration on this channel (equivalent to calling enableVibration(boolean) with true). Otherwise, vibration will be disabled unless enableVibration(boolean) is used with true, in which case the default vibration will be used. Only modifiable before the channel is submitted to NotificationManager#createNotificationChannel(NotificationChannel).

shouldShowLights

Added in API level 26
fun shouldShowLights(): Boolean

Returns whether notifications posted to this channel trigger notification lights.

shouldVibrate

Added in API level 26
fun shouldVibrate(): Boolean

Returns whether notifications posted to this channel always vibrate.

toString

Added in API level 26
fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 26
fun writeToParcel(
    dest: Parcel,
    flags: Int
): Unit
Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 26
static val CREATOR: Parcelable.Creator<NotificationChannel!>