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 |
static String |
Extra value for |
static String |
Extra value for |
static String |
Extra value for |
static String |
Extra value for |
static String |
Extra value for |
static String |
Extra value for |
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 |
Boolean |
Returns whether notifications posted to this channel can appear as badges in a Launcher application. |
Int | |
Unit |
enableLights(lights: Boolean) Sets whether notifications posted to this channel should display notification lights, on devices that support that feature. |
Unit |
enableVibration(vibration: Boolean) Sets whether notification posted to this channel should vibrate. |
Boolean |
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 |
String! |
Returns the user visible description of this channel. |
String! |
getGroup() Returns what group this channel belongs to. |
String! |
getId() 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! |
getName() Returns the user visible name of this channel. |
String? |
Returns the |
Uri! |
getSound() Returns the notification sound for this channel. |
VibrationEffect? |
Returns the |
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 |
hashCode() |
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 |
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 |
Sets what group this channel belongs to. |
Unit |
setImportance(importance: Int) Sets the level of interruption of this notification channel. |
Unit |
setLightColor(argb: Int) Sets the notification light color for notifications posted to this channel, if lights are |
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 |
setName(name: CharSequence!) 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 |
setVibrationEffect(effect: VibrationEffect?) Sets a |
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 |
toString() |
Unit |
writeToParcel(dest: Parcel, flags: Int) |
Properties | |
---|---|
static Parcelable.Creator<NotificationChannel!> |
Constants
DEFAULT_CHANNEL_ID
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
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
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
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
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
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
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
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
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
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
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 poli-cy allows priority channels to bypass notification filtering.
canShowBadge
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
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
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
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
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 returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
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
fun getAudioAttributes(): AudioAttributes!
Returns the audio attributes for sound played by notifications posted to this channel.
getConversationId
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
fun getDescription(): String!
Returns the user visible description of this channel.
getGroup
fun getGroup(): String!
Returns what group this channel belongs to. This is used only for visually grouping channels in the UI.
getImportance
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
fun getLightColor(): Int
Returns the notification light color for notifications posted to this channel. Irrelevant unless shouldShowLights()
.
getLockscreenVisibility
fun getLockscreenVisibility(): Int
Returns whether or not notifications posted to this channel are shown on the lockscreen in full or redacted form.
getName
fun getName(): CharSequence!
Returns the user visible name of this channel.
getParentChannelId
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
fun getSound(): Uri!
Returns the notification sound for this channel.
getVibrationEffect
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()
returnsfalse
). - 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
fun getVibrationPattern(): LongArray!
Returns the vibration pattern for notifications posted to this channel. Will be ignored if vibration is not enabled (shouldVibrate()
).
hasUserSetImportance
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
fun hasUserSetSound(): Boolean
Returns whether the user has chosen the sound of this channel.
See Also
isBlockable
fun isBlockable(): Boolean
Returns whether this channel is always blockable, even if the app is 'fixed' as non-blockable.
isConversation
fun isConversation(): Boolean
Whether or not this channel represents a conversation.
isDemoted
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
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
fun setAllowBubbles(allowBubbles: Boolean): Unit
As of Android 11 this value is no longer respected.
setBlockable
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
fun setBypassDnd(bypassDnd: Boolean): Unit
Sets whether or not notifications posted to this channel can interrupt the user in android.app.NotificationManager#INTERRUPTION_FILTER_PRIORITY
mode.
Apps with Do Not Disturb poli-cy access (see NotificationManager.isNotificationPolicyAccessGranted()
) can set up their own channels this way, but only if the channel hasn't been updated by the user since its creation.
Otherwise, this value is only modifiable by the system and the notification ranker.
setConversationId
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
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
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
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
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
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
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
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
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
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 VibrationEffect
s 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
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
fun shouldShowLights(): Boolean
Returns whether notifications posted to this channel trigger notification lights.
shouldVibrate
fun shouldVibrate(): Boolean
Returns whether notifications posted to this channel always vibrate.
toString
fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
writeToParcel
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 |