# Class NotificationChannelBuilder

java.lang.Object
com.codename1.notifications.NotificationChannelBuilder

public class NotificationChannelBuilder extends java.lang.Object

Builds and registers a notification channel. Notification channels are an Android concept (introduced in Android O) that let the user control the behavior of groups of notifications: importance, sound, vibration, lights, lockscreen visibility and whether a badge is shown. Once a channel is created its user-controllable settings cannot be changed programmatically, so build it once at app startup.

On platforms without a channel concept (iOS, desktop) registering a channel is a no-op, but the channel id you assign to a `LocalNotification` is still carried so the notification behaves consistently.

Usage

    new NotificationChannelBuilder("messages", "Messages")
            .description("Incoming chat messages")
            .importance(NotificationChannelBuilder.IMPORTANCE_HIGH)
            .sound("/notification_sound_ping.mp3")
            .enableVibration(true)
            .register();

##### See also

- LocalNotification#setChannelId(String)

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `IMPORTANCE_DEFAULT`
  Channel importance: shows everywhere, makes noise but does not visually intrude.
  `static final int`
  `IMPORTANCE_HIGH`
  Channel importance: makes noise and shows as a heads-up notification.
  `static final int`
  `IMPORTANCE_LOW`
  Channel importance: shows in the shade and status bar but is not intrusive.
  `static final int`
  `IMPORTANCE_MAX`
  Channel importance: the highest level (rarely needed).
  `static final int`
  `IMPORTANCE_MIN`
  Channel importance: shows nowhere, is not intrusive.
  `static final int`
  `IMPORTANCE_NONE`
  Channel importance: a no-importance channel does not appear in the shade.
  `static final int`
  `VISIBILITY_PRIVATE`
  Lockscreen visibility: show the notification but hide sensitive content on a secure lockscreen.
  `static final int`
  `VISIBILITY_PUBLIC`
  Lockscreen visibility: show the notification in its entirety on the lockscreen.
  `static final int`
  `VISIBILITY_SECRET`
  Lockscreen visibility: do not reveal any part of the notification on a secure lockscreen.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NotificationChannelBuilder(String id, String name)`
  Creates a channel builder.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `createChannelGroup(String groupId, String groupName)`
  Creates a channel group, which visually groups channels in the system settings.
  `static void`
  `deleteChannel(String id)`
  Deletes a previously registered channel.
  `NotificationChannelBuilder`
  `description(String d)`
  Sets the user-visible channel description.
  `NotificationChannelBuilder`
  `enableLights(boolean b)`
  Enables or disables the notification light for this channel.
  `NotificationChannelBuilder`
  `enableVibration(boolean b)`
  Enables or disables vibration for this channel.
  `String`
  `getDescription()`
  Returns the channel description.
  `String`
  `getGroup()`
  Returns the channel group id.
  `String`
  `getId()`
  Returns the channel id.
  `int`
  `getImportance()`
  Returns the channel importance.
  `int`
  `getLightColor()`
  Returns the light color.
  `int`
  `getLockscreenVisibility()`
  Returns the lockscreen visibility.
  `String`
  `getName()`
  Returns the user-visible channel name.
  `String`
  `getSound()`
  Returns the channel sound file path.
  `long[]`
  `getVibrationPattern()`
  Returns the vibration pattern.
  `NotificationChannelBuilder`
  `group(String groupId)`
  Assigns this channel to a channel group.
  `NotificationChannelBuilder`
  `importance(int imp)`
  Sets the channel importance, one of the `IMPORTANCE_` constants.
  `boolean`
  `isLightsEnabled()`
  Returns true if lights are enabled.
  `boolean`
  `isShowBadge()`
  Returns true if a launcher badge is allowed.
  `boolean`
  `isVibrationEnabled()`
  Returns true if vibration is enabled.
  `NotificationChannelBuilder`
  `lightColor(int rgb)`
  Sets the notification light color (as an RGB integer) and enables lights.
  `NotificationChannelBuilder`
  `lockscreenVisibility(int v)`
  Sets the lockscreen visibility, one of the `VISIBILITY_` constants.
  `void`
  `register()`
  Registers this channel with the platform.
  `NotificationChannelBuilder`
  `showBadge(boolean b)`
  Controls whether notifications on this channel may show a launcher badge.
  `NotificationChannelBuilder`
  `sound(String soundFile)`
  Sets the sound played for notifications on this channel.
  `NotificationChannelBuilder`
  `vibrationPattern(long[] pattern)`
  Sets the vibration pattern (alternating off/on durations in milliseconds) and enables vibration.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### IMPORTANCE_NONE

    public static final int IMPORTANCE_NONE
    Channel importance: a no-importance channel does not appear in the shade.
    See Also:
      - Constant Field Values

  - ### IMPORTANCE_MIN

    public static final int IMPORTANCE_MIN
    Channel importance: shows nowhere, is not intrusive.
    See Also:
      - Constant Field Values

  - ### IMPORTANCE_LOW

    public static final int IMPORTANCE_LOW
    Channel importance: shows in the shade and status bar but is not intrusive.
    See Also:
      - Constant Field Values

  - ### IMPORTANCE_DEFAULT

    public static final int IMPORTANCE_DEFAULT
    Channel importance: shows everywhere, makes noise but does not visually intrude.
    See Also:
      - Constant Field Values

  - ### IMPORTANCE_HIGH

    public static final int IMPORTANCE_HIGH
    Channel importance: makes noise and shows as a heads-up notification.
    See Also:
      - Constant Field Values

  - ### IMPORTANCE_MAX

    public static final int IMPORTANCE_MAX
    Channel importance: the highest level (rarely needed).
    See Also:
      - Constant Field Values

  - ### VISIBILITY_SECRET

    public static final int VISIBILITY_SECRET
    Lockscreen visibility: do not reveal any part of the notification on a secure lockscreen.
    See Also:
      - Constant Field Values

  - ### VISIBILITY_PRIVATE

    public static final int VISIBILITY_PRIVATE
    Lockscreen visibility: show the notification but hide sensitive content on a secure lockscreen.
    See Also:
      - Constant Field Values

  - ### VISIBILITY_PUBLIC

    public static final int VISIBILITY_PUBLIC
    Lockscreen visibility: show the notification in its entirety on the lockscreen.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### NotificationChannelBuilder

    public NotificationChannelBuilder(String id, String name)

    Creates a channel builder.

    ###### Parameters

    - `id`: a stable channel id used when posting notifications

    - `name`: the user-visible channel name shown in the system settings

- ## Method Details

  - ### description

    public NotificationChannelBuilder description(String d)

    Sets the user-visible channel description.

    ###### Parameters

    - `d`: the description

    ###### Returns

    this builder for chaining

  - ### importance

    public NotificationChannelBuilder importance(int imp)

    Sets the channel importance, one of the `IMPORTANCE_` constants.

    ###### Parameters

    - `imp`: the importance level

    ###### Returns

    this builder for chaining

  - ### sound

    public NotificationChannelBuilder sound(String soundFile)

    Sets the sound played for notifications on this channel. The file name must start with the "notification_sound" prefix and be bundled with the app.

    ###### Parameters

    - `soundFile`: the sound file path

    ###### Returns

    this builder for chaining

  - ### enableVibration

    public NotificationChannelBuilder enableVibration(boolean b)

    Enables or disables vibration for this channel.

    ###### Parameters

    - `b`: true to enable vibration

    ###### Returns

    this builder for chaining

  - ### vibrationPattern

    public NotificationChannelBuilder vibrationPattern(long[] pattern)

    Sets the vibration pattern (alternating off/on durations in milliseconds) and enables vibration.

    ###### Parameters

    - `pattern`: the vibration pattern

    ###### Returns

    this builder for chaining

  - ### enableLights

    public NotificationChannelBuilder enableLights(boolean b)

    Enables or disables the notification light for this channel.

    ###### Parameters

    - `b`: true to enable lights

    ###### Returns

    this builder for chaining

  - ### lightColor

    public NotificationChannelBuilder lightColor(int rgb)

    Sets the notification light color (as an RGB integer) and enables lights.

    ###### Parameters

    - `rgb`: the light color

    ###### Returns

    this builder for chaining

  - ### lockscreenVisibility

    public NotificationChannelBuilder lockscreenVisibility(int v)

    Sets the lockscreen visibility, one of the `VISIBILITY_` constants.

    ###### Parameters

    - `v`: the lockscreen visibility

    ###### Returns

    this builder for chaining

  - ### group

    public NotificationChannelBuilder group(String groupId)

    Assigns this channel to a channel group. The group must be created with `#createChannelGroup(String, String)` before or after the channel is registered.

    ###### Parameters

    - `groupId`: the channel group id

    ###### Returns

    this builder for chaining

  - ### showBadge

    public NotificationChannelBuilder showBadge(boolean b)

    Controls whether notifications on this channel may show a launcher badge.

    ###### Parameters

    - `b`: true to allow a badge

    ###### Returns

    this builder for chaining

  - ### getId

    public String getId()

    Returns the channel id.

    ###### Returns

    the channel id

  - ### getName

    public String getName()

    Returns the user-visible channel name.

    ###### Returns

    the channel name

  - ### getDescription

    public String getDescription()

    Returns the channel description.

    ###### Returns

    the description, or null

  - ### getImportance

    public int getImportance()

    Returns the channel importance.

    ###### Returns

    the importance level

  - ### getSound

    public String getSound()

    Returns the channel sound file path.

    ###### Returns

    the sound file, or null

  - ### isVibrationEnabled

    public boolean isVibrationEnabled()

    Returns true if vibration is enabled.

    ###### Returns

    true if vibration is enabled

  - ### getVibrationPattern

    public long[] getVibrationPattern()

    Returns the vibration pattern.

    ###### Returns

    the vibration pattern, or null

  - ### isLightsEnabled

    public boolean isLightsEnabled()

    Returns true if lights are enabled.

    ###### Returns

    true if lights are enabled

  - ### getLightColor

    public int getLightColor()

    Returns the light color.

    ###### Returns

    the light color as an RGB integer

  - ### getLockscreenVisibility

    public int getLockscreenVisibility()

    Returns the lockscreen visibility.

    ###### Returns

    the lockscreen visibility

  - ### getGroup

    public String getGroup()

    Returns the channel group id.

    ###### Returns

    the group id, or null

  - ### isShowBadge

    public boolean isShowBadge()

    Returns true if a launcher badge is allowed.

    ###### Returns

    true if a badge is allowed

  - ### register

    public void register()
    Registers this channel with the platform. On platforms without channels this is a no-op.

  - ### deleteChannel

    public static void deleteChannel(String id)

    Deletes a previously registered channel. On platforms without channels this is a no-op.

    ###### Parameters

    - `id`: the channel id to delete

  - ### createChannelGroup

    public static void createChannelGroup(String groupId, String groupName)

    Creates a channel group, which visually groups channels in the system settings. On platforms without channels this is a no-op.

    ###### Parameters

    - `groupId`: a stable group id

    - `groupName`: the user-visible group name