Class WonderPushChannel

java.lang.Object
com.wonderpush.sdk.WonderPushChannel
All Implemented Interfaces:
Cloneable

public class WonderPushChannel extends Object implements Cloneable
A representation of settings that apply to a collection of similarly themed notifications.

This class mimicks the NotificationChannel class to permit exposing its benefits to devices prior to Android O. Contrary to the latter, this class permits to override only a few aspects of the notification.

It also contains some additions that may no longer be available under Android O where the user is in full control of these settings, such as preventing a notification that usually makes a sound or vibrates to vibrate while the device is in silent mode.
Some feature like the color should remain configurable using this class under Android O.

See Also:
  • NotificationChannel
  • Constructor Details

    • WonderPushChannel

      public WonderPushChannel(@NonNull String id, String groupId)
      Create a notification channel.
      Parameters:
      id - The id of the channel. Must be unique per package. The value may be truncated if it is too long.
      groupId - The id of a channel group. You should create the group prior to creating this channel.
      See Also:
      • NotificationChannel(java.lang.String, java.lang.CharSequence, int)
  • Method Details

    • clone

      public Object clone() throws CloneNotSupportedException
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getId

      public String getId()
      Returns the id of this channel.
      See Also:
      • NotificationChannel.getId()
    • getGroupId

      public String getGroupId()
      Returns what group this channel belongs to. This is used only for visually grouping channels in the UI. Can be null.
      Returns:
      The id of the group this channel belongs to, if any.
      See Also:
      • NotificationChannel.setGroup(String)
    • getName

      public String getName()
      Returns the user visible name of this channel.
      See Also:
      • NotificationChannel.getName()
    • setName

      public WonderPushChannel setName(String name)
      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.
      Parameters:
      name - The user visible name of this channel.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setName(CharSequence)
    • getDescription

      public String getDescription()
      Returns the user visible description of this channel.
      Returns:
      The user visible description of this channel.
      See Also:
      • NotificationChannel.getDescription()
    • setDescription

      public WonderPushChannel setDescription(String description)
      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.
      Parameters:
      description - The user visible description of this channel.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setDescription(String)
    • getBypassDnd

      public Boolean getBypassDnd()
      Whether or not notifications posted to this channel can bypass the Do Not Disturb NotificationManager.INTERRUPTION_FILTER_PRIORITY mode.
      Returns:
      whether or not notifications posted to this channel can bypass the Do Not Disturb NotificationManager.INTERRUPTION_FILTER_PRIORITY mode.
    • setBypassDnd

      public WonderPushChannel setBypassDnd(Boolean bypassDnd)
      Sets whether or not notifications posted to this channel can interrupt the user in NotificationManager.INTERRUPTION_FILTER_PRIORITY mode. Only modifiable by the system and notification ranker.
      Parameters:
      bypassDnd - whether or not notifications posted to this channel can interrupt the user in NotificationManager.INTERRUPTION_FILTER_PRIORITY mode.
      Returns:
      The channel object for chaining setters.
    • getShowBadge

      public Boolean getShowBadge()
      Returns whether notifications posted to this channel can appear as badges in a Launcher application. Note that badging may be disabled for other reasons.
      Returns:
      whether notifications posted to this channel can appear as badges in a Launcher application. Note that badging may be disabled for other reasons.
    • setShowBadge

      public WonderPushChannel setShowBadge(Boolean showBadge)
      Sets whether notifications posted to this channel can appear as application icon badges in a Launcher.
      Parameters:
      showBadge - true if badges should be allowed to be shown.
      Returns:
      The channel object for chaining setters.
    • getImportance

      public Integer getImportance()
      Returns the user specified importance for notifications posted to this channel. Example: NotificationManager.IMPORTANCE_DEFAULT
      Returns:
      The user specified importance for notifications posted to this channel. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getImportance()
    • setImportance

      public WonderPushChannel setImportance(Integer importance)
      Sets the level of interruption of this notification channel. Example: NotificationManager.IMPORTANCE_DEFAULT
      Parameters:
      importance - The level of interruption of this notification channel. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setImportance(int)
    • getLights

      public Boolean getLights()
      Returns whether notifications posted to this channel trigger notification lights.
      Returns:
      Whether notifications posted to this channel trigger notification lights. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.shouldShowLights()
    • setLights

      public WonderPushChannel setLights(Boolean lights)
      Sets whether notifications posted to this channel should display notification lights, on devices that support that feature.
      Parameters:
      lights - Whether notifications posted to this channel should display notification lights Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.enableLights(boolean)
    • getVibrate

      public Boolean getVibrate()
      Returns whether notifications posted to this channel always vibrate.
      Returns:
      Whether notifications posted to this channel always vibrate. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.shouldVibrate()
    • setVibrate

      public WonderPushChannel setVibrate(Boolean vibrate)
      Sets whether notification posted to this channel should vibrate. The vibration pattern can be set with setVibrationPattern(long[]).
      Parameters:
      vibrate - Whether notification posted to this channel should vibrate. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.enableVibration(boolean)
    • getVibrationPattern

      public long[] getVibrationPattern()
      Returns the vibration pattern for notifications posted to this channel.
      Returns:
      The vibration pattern for notifications posted to this channel. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getVibrationPattern()
    • setVibrationPattern

      public WonderPushChannel setVibrationPattern(long[] vibrationPattern)
      Sets the vibration pattern for notifications posted to this channel.
      Parameters:
      vibrationPattern - The vibration pattern for notifications posted to this channel. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setVibrationPattern(long[])
    • getLightColor

      public Integer getLightColor()
      Sets the notification light color for notifications posted to this channel, if lights are enabled on this channel and the device supports that feature.
      Returns:
      The notification light color for notifications posted to this channel Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getLightColor()
    • setLightColor

      public WonderPushChannel setLightColor(Integer lightColor)
      Returns the notification light color for notifications posted to this channel.
      Parameters:
      lightColor - The notification light color for notifications posted to this channel. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setLightColor(int)
    • getLockscreenVisibility

      public Integer getLockscreenVisibility()
      Returns whether or not notifications posted to this channel are shown on the lockscreen in full or redacted form.
      Returns:
      Whether or not notifications posted to this channel are shown on the lockscreen in full or redacted form. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getLockscreenVisibility()
    • setLockscreenVisibility

      public WonderPushChannel setLockscreenVisibility(Integer lockscreenVisibility)
      Sets whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form. Example: Notification.VISIBILITY_PUBLIC.
      Parameters:
      lockscreenVisibility - Whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setLockscreenVisibility(int)
    • getSound

      public Boolean getSound()
      Returns whether a sound should be played for notifications posted to this channel.
      Returns:
      Whether a sound should be played for notifications posted to this channel. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getSound()
    • setSound

      public WonderPushChannel setSound(Boolean sound)
      Sets whether a sound should be played for notifications posted to this channel.
      Parameters:
      sound - Whether a sound should be played for notifications posted to this channel. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setSound(android.net.Uri, android.media.AudioAttributes)
    • getSoundUri

      public android.net.Uri getSoundUri()
      Returns the notification sound for this channel.
      Returns:
      The notification sound for this channel. Returns null if this setting does not override the received notifications setting.
      See Also:
      • NotificationChannel.getSound()
    • setSoundUri

      public WonderPushChannel setSoundUri(android.net.Uri soundUri)
      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.
      Parameters:
      soundUri - The sound that should be played for notifications posted to this channel. You can use Settings.System.DEFAULT_NOTIFICATION_URI to use the default notification sound. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • NotificationChannel.setSound(android.net.Uri, android.media.AudioAttributes)
    • getVibrateInSilentMode

      public Boolean getVibrateInSilentMode()
      Returns whether notifications posted to this channel vibrate if the device is in silent mode.

      This is a WonderPush addition.

      The primary use of this flag is to permit notifications with sound and vibration in normal mode but prevent it from vibrating in all cases in silent mode.

      Returns:
      Whether notifications posted to this channel vibrate if the device is in silent mode. Returns null if this setting does not override the received notifications setting.
    • setVibrateInSilentMode

      public WonderPushChannel setVibrateInSilentMode(Boolean vibrateInSilentMode)
      Sets whether notifications posted to this channel vibrate if the device is in silent mode.

      This is a WonderPush addition.

      The primary use of this flag is to permit notifications with sound and vibration in normal mode but prevent it from vibrating in all cases in silent mode.

      Note: You can control this setting irrespective of the fact that a given notification should vibrate a make a sound in normal mode.

      Parameters:
      vibrateInSilentMode - Whether notifications posted to this channel vibrate if the device is in silent mode. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
    • getColor

      public Integer getColor()
      Returns the color to impose on all notifications posted to this channel.

      This is independent of Android O notification channels and should continue to work under Android O.

      Returns:
      The color to impose on all notifications posted to this channel. Returns null if this setting does not override the received notifications setting.
      See Also:
      • Notification.Builder.setColor(int)
    • setColor

      public WonderPushChannel setColor(Integer color)
      Sets the color to impose on all notifications posted to this channel.

      This is independent of Android O notification channels and should continue to work under Android O.

      Parameters:
      color - The color to impose on all notifications posted to this channel. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • Notification.Builder.setColor(int)
    • getLocalOnly

      public Boolean getLocalOnly()
      Returns whether notifications posted to this channel should be local to this device.

      This is independent of Android O notification channels and should continue to work under Android O.

      Returns:
      Whether notifications posted to this channel should be local to this device. Returns null if this setting does not override the received notifications setting.
      See Also:
      • Notification.Builder.setLocalOnly(boolean)
    • setLocalOnly

      public WonderPushChannel setLocalOnly(Boolean localOnly)
      Sets whether notifications posted to this channel should be local to this device.

      This is independent of Android O notification channels and should continue to work under Android O.

      Parameters:
      localOnly - Whether notifications posted to this channel should be local to this device. Use null to not override the received notifications setting.
      Returns:
      The channel object for chaining setters.
      See Also:
      • Notification.Builder.setLocalOnly(boolean)