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.
[Expand]
Inherited Fields
From class com.urbanairship.AirshipComponent
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.
boolean areNotificationsOptedIn()
Checks if notifications are enabled for the app and in the push manager.
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.
NotificationListener getNotificationListener()
Gets the notification listener.
NotificationProvider getNotificationProvider()
Gets the notification provider.
String getPushToken()
Gets the push token.
Date[] getQuietTimeInterval()
This method is deprecated. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean getUserNotificationsEnabled()
Determines whether user-facing push notifications are enabled.
boolean isInQuietTime()
This method is deprecated. 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()
This method is deprecated. Enable/disable by enabling FEATURE_PUSH in PrivacyManager. This will call through to the privacy manager.
boolean isPushTokenRegistrationEnabled()
This method is deprecated. Check if FEATURE_PUSH is enabled in the PrivacyManager.
boolean isQuietTimeEnabled()
This method is deprecated. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean isSoundEnabled()
This method is deprecated. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
boolean isVibrateEnabled()
This method is deprecated. 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 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)
This method is deprecated. Enable/disable by enabling FEATURE_PUSH in PrivacyManager. This will call through to the privacy manager.
void setPushTokenRegistrationEnabled(boolean enabled)
This method is deprecated. Enable/disable FEATURE_PUSH in the PrivacyManager.
void setQuietTimeEnabled(boolean enabled)
This method is deprecated. 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. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void setSoundEnabled(boolean enabled)
This method is deprecated. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
void setUserNotificationsEnabled(boolean enabled)
Enables or disables user notifications.
void setVibrateEnabled(boolean enabled)
This method is deprecated. This setting does not work on Android O+. Applications are encouraged to use NotificationChannelCompat instead.
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 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 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 NotificationListener getNotificationListener ()

Gets the notification listener.

Returns
  • The notification listener.

public NotificationProvider getNotificationProvider ()

Gets the notification provider.

Returns
  • The notification provider.

public String getPushToken ()

Gets the push token.

Returns
  • The push token.

public Date[] getQuietTimeInterval ()

This method is deprecated.
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 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.
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 ()

This method is deprecated.
Enable/disable by enabling FEATURE_PUSH in PrivacyManager. This will call through to the privacy manager.

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 isPushTokenRegistrationEnabled ()

This method is deprecated.
Check if FEATURE_PUSH is enabled in the PrivacyManager.

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

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

public boolean isQuietTimeEnabled ()

This method is deprecated.
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.
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.
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 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)

This method is deprecated.
Enable/disable by enabling FEATURE_PUSH in PrivacyManager. This will call through to the privacy manager.

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)

This method is deprecated.
Enable/disable FEATURE_PUSH in the PrivacyManager.

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.
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.
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.
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 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.
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.

Protected Methods

protected void init ()

Initialize the manager. Called in UAirship during takeoff.