Google is committed to advancing racial equity for Black communities. See how.

Builder

open class Builder
kotlin.Any
   ↳ androidx.core.app.NotificationChannelCompat.Builder

Builder class for NotificationChannelCompat objects.

Summary

Public constructors
<init>(@NonNull id: String, importance: Int)

Creates a notification channel builder.

Public methods
open NotificationChannelCompat

Creates a NotificationChannelCompat instance.

open NotificationChannelCompat.Builder
setConversationId(@NonNull parentChannelId: String, @NonNull conversationId: String)

Sets this channel as being conversation-centric.

open NotificationChannelCompat.Builder
setDescription(@Nullable description: String?)

Sets the user visible description of this channel.

open NotificationChannelCompat.Builder
setGroup(@Nullable groupId: String?)

Sets what group this channel belongs to.

open NotificationChannelCompat.Builder
setImportance(importance: Int)

Sets the level of interruption of this notification channel.

open NotificationChannelCompat.Builder

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

open NotificationChannelCompat.Builder

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

open NotificationChannelCompat.Builder
setName(@Nullable name: CharSequence?)

Sets the user visible name of this channel.

open NotificationChannelCompat.Builder
setShowBadge(showBadge: Boolean)

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

open NotificationChannelCompat.Builder
setSound(@Nullable sound: Uri?, @Nullable audioAttributes: AudioAttributes?)

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

open NotificationChannelCompat.Builder

Sets whether notification posted to this channel should vibrate.

open NotificationChannelCompat.Builder
setVibrationPattern(@Nullable vibrationPattern: LongArray?)

Sets the vibration pattern for notifications posted to this channel.

Public constructors

<init>

Builder(
    @NonNull id: String,
    importance: Int)

Creates a notification channel builder.

Parameters
id String: The id of the channel. Must be unique per package. 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.

Public methods

build

@NonNull open fun build(): NotificationChannelCompat

Creates a NotificationChannelCompat instance.

setConversationId

@NonNull open fun setConversationId(
    @NonNull parentChannelId: String,
    @NonNull conversationId: String
): NotificationChannelCompat.Builder

Sets this channel as being conversation-centric. Different settings and functionality may be exposed for conversation-centric channels. Calling this on SDKs that do not support conversations will have no effect on the built channel. As a result, this channel will not be linked to the channel with the parentChannelId. That means that this channel must be published to directly to be used; it cannot be published to by publishing to the parentChannelId with the shortcutId.

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.'
conversationId String: The ShortcutInfoCompat#getId() of the shortcut representing this channel's conversation.

setDescription

@NonNull open fun setDescription(@Nullable description: String?): NotificationChannelCompat.Builder

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

@NonNull open fun setGroup(@Nullable groupId: String?): NotificationChannelCompat.Builder

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 NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat), unless the channel is not currently part of a group.

Parameters
groupId String?: the id of a group created by NotificationManagerCompat#createNotificationChannelGroup.

setImportance

@NonNull open fun setImportance(importance: Int): NotificationChannelCompat.Builder

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

Parameters
importance Int: the amount the user should be interrupted by notifications from this channel.

setLightColor

@NonNull open fun setLightColor(argb: Int): NotificationChannelCompat.Builder

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 NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat).

setLightsEnabled

@NonNull open fun setLightsEnabled(lights: Boolean): NotificationChannelCompat.Builder

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 NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat).

setName

@NonNull open fun setName(@Nullable name: CharSequence?): NotificationChannelCompat.Builder

Sets the user visible name of this 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.

setShowBadge

@NonNull open fun setShowBadge(showBadge: Boolean): NotificationChannelCompat.Builder

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

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

setSound

@NonNull open fun setSound(
    @Nullable sound: Uri?,
    @Nullable audioAttributes: AudioAttributes?
): NotificationChannelCompat.Builder

Sets the sound that should be played for notifications posted to this channel and its audio attributes. Notification channels with an setImportance(int) importance} of at least NotificationManagerCompat#IMPORTANCE_DEFAULT should have a sound. Only modifiable before the channel is submitted to NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat).

setVibrationEnabled

@NonNull open fun setVibrationEnabled(vibration: Boolean): NotificationChannelCompat.Builder

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 NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat).

setVibrationPattern

@NonNull open fun setVibrationPattern(@Nullable vibrationPattern: LongArray?): NotificationChannelCompat.Builder

Sets the vibration pattern for notifications posted to this channel. If the provided pattern is valid (non-null, non-empty), will setVibrationEnabled(boolean) enable vibration} as well. Otherwise, vibration will be disabled. Only modifiable before the channel is submitted to NotificationManagerCompat#createNotificationChannel(NotificationChannelCompat).