public class

PushManager

extends AirshipComponent
java.lang.Object
   ↳ com.urbanairship.AirshipComponent
     ↳ com.urbanairship.push.PushManager

Class Overview

This class is the primary interface for customizing the display and behavior of incoming push notifications.

Summary

Constants
String EXTRA_NOTIFICATION_ID The notification ID extra contains the ID of the notification placed in the NotificationManager by the library.
String EXTRA_NOTIFICATION_TAG The notification tag extra contains the tag of the notification placed in the NotificationManager by the library.
Public Methods
void addNotificationActionButtonGroup(String id, NotificationActionButtonGroup group)
Register a notification action group under the given name.
void addNotificationActionButtonGroups(Context context, int resId)
Adds notification action button groups from an xml file.
void addPushListener(PushListener listener)
Adds a push listener.
void addPushTokenListener(PushTokenListener listener)
Adds a push token listener.
void addRegistrationListener(RegistrationListener listener)
This method is deprecated. Use addChannelListener(AirshipChannelListener) and/or addPushTokenListener(PushTokenListener) instead. Will be removed in SDK 13.
boolean areNotificationsOptedIn()
Checks if notifications are enabled for the app and in the push manager.
TagGroupsEditor editTagGroups()
This method is deprecated. Will be removed in SDK 13. Use editTagGroups() instead.
TagEditor editTags()
This method is deprecated. Will be removed in SDK 13. Use editTags() instead.
void enableChannelCreation()
This method is deprecated. Will be removed in SDK 13. Use enableChannelCreation() instead.
String getChannelId()
This method is deprecated. Will be removed in SDK 13. Use getId() instead.
boolean getChannelTagRegistrationEnabled()
This method is deprecated. Will be removed in SDK 13. Use getChannelTagRegistrationEnabled() instead.
String getLastReceivedMetadata()
Returns the send metadata of the last received push.
NotificationActionButtonGroup getNotificationActionGroup(String id)
Returns the notification action group that is registered under the given name.
NotificationChannelRegistry getNotificationChannelRegistry()
Returns the shared notification channel registry.
NotificationProvider getNotificationProvider()
Gets the notification provider.
String getPushToken()
Gets the push token.
boolean getPushTokenRegistrationEnabled()
Determines whether the push token is sent during channel registration.
Date[] getQuietTimeInterval()
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
String getRegistrationToken()
This method is deprecated. Use getPushToken() instead.
Set<String> getTags()
This method is deprecated. Will be removed in SDK 13. Use getTags() instead.
boolean getUserNotificationsEnabled()
Determines whether user-facing push notifications are enabled.
boolean isInQuietTime()
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean isOptIn()
Returns if the application is currently opted in for push.
boolean isPushAvailable()
Determines whether the app is capable of receiving push, meaning whether a FCM or ADM push token is present.
boolean isPushEnabled()
Determines whether push is enabled.
boolean isQuietTimeEnabled()
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean isSoundEnabled()
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean isVibrateEnabled()
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void removeNotificationActionButtonGroup(String id)
Removes the notification button group under the given name.
void removePushListener(PushListener listener)
Removes a push listener.
void removePushTokenListener(PushTokenListener listener)
Removes a push token listener.
void removeRegistrationListener(RegistrationListener listener)
Removes a registration listener.
void setChannelTagRegistrationEnabled(boolean enabled)
This method is deprecated. Will be removed in SDK 13. Use setChannelTagRegistrationEnabled(boolean) instead.
void setNotificationFactory(NotificationFactory factory)
This method is deprecated. Use NotificationProvider and setNotificationProvider(NotificationProvider) instead. To be removed in SDK 11.
void setNotificationListener(NotificationListener listener)
Sets the notification listener.
void setNotificationProvider(NotificationProvider provider)
Sets the notification provider used to build notifications from a push message If null, notification will not be displayed.
void setPushEnabled(boolean enabled)
Enables or disables push notifications.
void setPushTokenRegistrationEnabled(boolean enabled)
Sets whether the push token is sent during channel registration.
void setQuietTimeEnabled(boolean enabled)
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void setQuietTimeInterval(Date startTime, Date endTime)
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void setSoundEnabled(boolean enabled)
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void setTags(Set<String> tags)
This method is deprecated. Will be removed in SDK 13. Use setTags(Set) instead.
void setUserNotificationsEnabled(boolean enabled)
Enables or disables user notifications.
void setVibrateEnabled(boolean enabled)
This method is deprecated. Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void updateRegistration()
This method is deprecated. Will be removed in SDk 13. There is no reason to ever use this method. It now no-ops.
Protected Methods
void init()
Initialize the manager.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String EXTRA_NOTIFICATION_ID

The notification ID extra contains the ID of the notification placed in the NotificationManager by the library.

If a Notification was not created, the extra will not be included.

Constant Value: "com.urbanairship.push.NOTIFICATION_ID"

public static final String EXTRA_NOTIFICATION_TAG

The notification tag extra contains the tag of the notification placed in the NotificationManager by the library.

If a Notification was not created, the extra will not be included.

Constant Value: "com.urbanairship.push.NOTIFICATION_TAG"

Public Methods

public void addNotificationActionButtonGroup (String id, NotificationActionButtonGroup group)

Register a notification action group under the given name.

The provided notification builders will automatically add the actions to the notification when a message is received with a group specified under the EXTRA_INTERACTIVE_TYPE key.

Parameters
id The id of the action group.
group The notification action group.

public void addNotificationActionButtonGroups (Context context, int resId)

Adds notification action button groups from an xml file. Example entry:

<UrbanAirshipActionButtonGroup id="custom_group">
  <UrbanAirshipActionButton
      foreground="true"
      id="yes"
      android:icon="@drawable/ua_ic_notification_button_accept"
      android:label="@string/ua_notification_button_yes"/>
  <UrbanAirshipActionButton
      foreground="false"
      id="no"
      android:icon="@drawable/ua_ic_notification_button_decline"
      android:label="@string/ua_notification_button_no"/>
 </UrbanAirshipActionButtonGroup> 

Parameters
context The application context.
resId The xml resource ID.

public void addPushListener (PushListener listener)

Adds a push listener.

Parameters
listener The push listener.

public void addPushTokenListener (PushTokenListener listener)

Adds a push token listener.

Parameters
listener The listener.

public void addRegistrationListener (RegistrationListener listener)

This method is deprecated.
Use addChannelListener(AirshipChannelListener) and/or addPushTokenListener(PushTokenListener) instead. Will be removed in SDK 13.

Adds a registration listener.

Parameters
listener The listener.

public boolean areNotificationsOptedIn ()

Checks if notifications are enabled for the app and in the push manager.

Returns
  • true if notifications are opted in, otherwise false.

public TagGroupsEditor editTagGroups ()

This method is deprecated.
Will be removed in SDK 13. Use editTagGroups() instead.

Edit the channel tag groups.

Returns

public TagEditor editTags ()

This method is deprecated.
Will be removed in SDK 13. Use editTags() instead.

Edits channel Tags.

Returns

public void enableChannelCreation ()

This method is deprecated.
Will be removed in SDK 13. Use enableChannelCreation() instead.

Enables channel creation if channel creation has been delayed.

This setting is persisted between application starts, so there is no need to call this repeatedly. It is only necessary to call this when channelCreationDelayEnabled has been set to true in the airship config.

public String getChannelId ()

This method is deprecated.
Will be removed in SDK 13. Use getId() instead.

Get the Channel ID

Returns
  • A Channel ID string

public boolean getChannelTagRegistrationEnabled ()

This method is deprecated.
Will be removed in SDK 13. Use getChannelTagRegistrationEnabled() instead.

Determines whether tags are enabled on the device. If false, no locally specified tags will be sent to the server during registration. The default value is true.

Returns
  • true if tags are enabled on the device, false otherwise.

public String getLastReceivedMetadata ()

Returns the send metadata of the last received push.

Returns
  • The send metadata from the last received push, or null if not found.

public NotificationActionButtonGroup getNotificationActionGroup (String id)

Returns the notification action group that is registered under the given name.

Parameters
id The id of the action group.
Returns
  • The notification action group.

public NotificationChannelRegistry getNotificationChannelRegistry ()

Returns the shared notification channel registry.

Returns
  • The NotificationChannelRegistry

public NotificationProvider getNotificationProvider ()

Gets the notification provider.

Returns
  • The notification provider.

public String getPushToken ()

Gets the push token.

Returns
  • The push token.

public boolean getPushTokenRegistrationEnabled ()

Determines whether the push token is sent during channel registration. If false, the app will not be able to receive push notifications. The default value is true.

Returns
  • true if the push token is sent during channel registration, false otherwise.

public Date[] getQuietTimeInterval ()

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Returns the Quiet Time interval currently set by the user.

Returns
  • An array of two Date instances, representing the start and end of Quiet Time.

public String getRegistrationToken ()

This method is deprecated.
Use getPushToken() instead.

Gets the push token.

Returns
  • The push token.

public Set<String> getTags ()

This method is deprecated.
Will be removed in SDK 13. Use getTags() instead.

Returns the current set of tags.

An empty set indicates that no tags are set on this channel.

Returns
  • The current set of tags.

public boolean getUserNotificationsEnabled ()

Determines whether user-facing push notifications are enabled.

Returns
  • true if user push is enabled, false otherwise.

public boolean isInQuietTime ()

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Determines whether we are currently in the middle of "Quiet Time". Returns false if Quiet Time is disabled, and evaluates whether or not the current date/time falls within the Quiet Time interval set by the user.

Returns
  • A boolean indicating whether it is currently "Quiet Time".

public boolean isOptIn ()

Returns if the application is currently opted in for push.

Returns
  • true if opted in for push.

public boolean isPushAvailable ()

Determines whether the app is capable of receiving push, meaning whether a FCM or ADM push token is present.

Returns
  • true if push is available, false otherwise.

public boolean isPushEnabled ()

Determines whether push is enabled.

Returns
  • true if push is enabled, false otherwise. This defaults to true, and must be explicitly set by the app.

public boolean isQuietTimeEnabled ()

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Determines whether "Quiet Time" is enabled.

Returns
  • A boolean indicating whether Quiet Time is enabled.

public boolean isSoundEnabled ()

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Determines whether sound is enabled.

Returns
  • A boolean indicated whether sound is enabled.

public boolean isVibrateEnabled ()

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Determines whether vibration is enabled.

Returns
  • A boolean indicating whether vibration is enabled.

public void removeNotificationActionButtonGroup (String id)

Removes the notification button group under the given name.

Parameters
id The id of the button group to remove.

public void removePushListener (PushListener listener)

Removes a push listener.

Parameters
listener The listener.

public void removePushTokenListener (PushTokenListener listener)

Removes a push token listener.

Parameters
listener The listener.

public void removeRegistrationListener (RegistrationListener listener)

Removes a registration listener.

Parameters
listener The listener.

public void setChannelTagRegistrationEnabled (boolean enabled)

This method is deprecated.
Will be removed in SDK 13. Use setChannelTagRegistrationEnabled(boolean) instead.

Sets whether tags are enabled on the device. The default value is true. If false, no locally specified tags will be sent to the server during registration.

Parameters
enabled A boolean indicating whether tags are enabled on the device.

public void setNotificationFactory (NotificationFactory factory)

This method is deprecated.
Use NotificationProvider and setNotificationProvider(NotificationProvider) instead. To be removed in SDK 11.

Sets the notification factory used when push notifications are received.

Specify a notification factory here to customize the display of a push notification's Custom Expanded Views in the Android Notification Manager.

If null, push notifications will not be displayed by the library.

Parameters
factory The notification factory

public void setNotificationListener (NotificationListener listener)

Sets the notification listener.

Parameters
listener The listener.

public void setNotificationProvider (NotificationProvider provider)

Sets the notification provider used to build notifications from a push message If null, notification will not be displayed.

Parameters
provider The notification provider

public void setPushEnabled (boolean enabled)

Enables or disables push notifications.

This setting is persisted between application starts, so there is no need to call this repeatedly. It is only necessary to call this when a user preference has changed.

Parameters
enabled A boolean indicating whether push is enabled.

public void setPushTokenRegistrationEnabled (boolean enabled)

Sets whether the push token is sent during channel registration. If false, the app will not be able to receive push notifications.

Parameters
enabled A boolean indicating whether the push token is sent during channel registration.

public void setQuietTimeEnabled (boolean enabled)

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Enables or disables quiet time.

Parameters
enabled A boolean indicating whether quiet time is enabled.

public void setQuietTimeInterval (Date startTime, Date endTime)

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Sets the Quiet Time interval.

Parameters
startTime A Date instance indicating when Quiet Time should start.
endTime A Date instance indicating when Quiet Time should end.

public void setSoundEnabled (boolean enabled)

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Enables or disables sound.

Parameters
enabled A boolean indicating whether sound is enabled.

public void setTags (Set<String> tags)

This method is deprecated.
Will be removed in SDK 13. Use setTags(Set) instead.

Set tags for the channel and update the server.

Tags should be URL-safe with a length greater than 0 and less than 127 characters. If your tag includes whitespace or special characters, we recommend URL encoding the string.

To clear the current set of tags, pass an empty set to this method.

Parameters
tags A set of tag strings.

public void setUserNotificationsEnabled (boolean enabled)

Enables or disables user notifications.

User notifications are push notifications that contain an alert message and are intended to be shown to the user.

This setting is persisted between application starts, so there is no need to call this repeatedly. It is only necessary to call this when a user preference has changed.

Parameters
enabled A boolean indicating whether user push is enabled.

public void setVibrateEnabled (boolean enabled)

This method is deprecated.
Will be removed in SDK 13. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.

Enables or disables vibration.

Parameters
enabled A boolean indicating whether vibration is enabled.

public void updateRegistration ()

This method is deprecated.
Will be removed in SDk 13. There is no reason to ever use this method. It now no-ops.

Update registration.

Protected Methods

protected void init ()

Initialize the manager. Called in UAirship during takeoff.