public class BrazeNotificationUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPBOY_NOTIFICATION_DELETED_SUFFIX
Deprecated.
Please
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_DELETED . Deprecated since 6/25/21 |
static java.lang.String |
APPBOY_NOTIFICATION_OPENED_SUFFIX
Deprecated.
Please see
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_OPENED . Deprecated since 6/25/21 |
static java.lang.String |
APPBOY_NOTIFICATION_RECEIVED_SUFFIX
Deprecated.
Please
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_OPENED . Deprecated since 6/25/21 |
Constructor and Description |
---|
BrazeNotificationUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
cancelNotification(android.content.Context context,
int notificationId)
Creates a request to cancel a push notification in the notification center.
|
static IBrazeNotificationFactory |
getActiveNotificationFactory()
Returns a custom AppboyNotificationFactory if set, else the default AppboyNotificationFactory
|
static android.os.Bundle |
getAppboyExtrasWithoutPreprocessing(android.os.Bundle notificationExtras)
Deprecated.
|
static int |
getNotificationId(BrazeNotificationPayload payload)
Returns an id for the new notification we'll send to the notification center.
|
static int |
getNotificationId(android.os.Bundle notificationExtras)
Deprecated.
Please use
getNotificationId(BrazeNotificationPayload) |
static int |
getNotificationPriority(android.os.Bundle notificationExtras)
This method will retrieve notification priority from notificationExtras bundle if it has been set.
|
static java.lang.Class<?> |
getNotificationReceiverClass() |
static java.lang.String |
getOrCreateNotificationChannelId(BrazeNotificationPayload payload)
Returns the channel id for a valid
NotificationChannel , creating one if necessary. |
static java.lang.String |
getOrCreateNotificationChannelId(android.content.Context context,
BrazeConfigurationProvider appConfigurationProvider,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
handleCancelNotificationAction(android.content.Context context,
android.content.Intent intent)
Handles a request to cancel a push notification in the notification center.
|
static void |
handleContentCardsSerializedCardIfPresent(BrazeNotificationPayload payload)
Parses the notification bundle for any associated
ContentCards, if present.
|
static void |
handleNotificationDeleted(android.content.Context context,
android.content.Intent intent)
Handles a push notification deletion by the user.
|
static void |
handleNotificationOpened(android.content.Context context,
android.content.Intent intent)
Handles a push notification click.
|
static void |
handlePushStoryPageClicked(android.content.Context context,
android.content.Intent intent)
Handles a push story page click.
|
static boolean |
isAppboyPushMessage(android.content.Intent intent)
Checks the incoming FCM/ADM intent to determine whether this is a Braze push message.
|
static boolean |
isInAppMessageTestPush(android.content.Intent intent)
Checks if a push
Intent contains extras found in a test push for in-app messages. |
static boolean |
isNotificationMessage(android.content.Intent intent)
Checks the intent received from FCM to determine whether this is a notification message or a
silent push.
|
static boolean |
isUninstallTrackingPush(android.os.Bundle notificationExtras)
Returns true if the bundle is from a push sent by Braze for uninstall tracking.
|
static boolean |
isValidNotificationVisibility(int visibility)
Checks whether the given integer value is a valid Android notification visibility constant.
|
static void |
logBaiduNotificationClick(android.content.Context context,
java.lang.String customContentString)
Logs a notification click with Braze if the extras passed down
indicate that they are from Braze and contain a campaign Id.
|
static android.os.Bundle |
parseJSONStringDictionaryIntoBundle(java.lang.String jsonStringDictionary)
Deprecated.
Please use
JsonUtils.parseJsonObjectIntoBundle(String) |
static void |
prefetchBitmapsIfNewlyReceivedStoryPush(android.content.Context context,
android.os.Bundle notificationExtras,
android.os.Bundle appboyExtras)
Checks that the notification is a story that has only just been received.
|
static boolean |
requestGeofenceRefreshIfAppropriate(android.content.Context context,
android.os.Bundle notificationExtras)
Requests a geofence refresh from Braze if appropriate based on the payload of the push notification.
|
static void |
routeUserWithNotificationOpenedIntent(android.content.Context context,
android.content.Intent intent)
Opens any available deep links with an Intent.ACTION_VIEW intent, placing the main activity
on the back stack.
|
static void |
sendPushMessageReceivedBroadcast(android.content.Context context,
android.os.Bundle notificationExtras)
Creates and sends a broadcast message that can be listened for by the host app.
|
static void |
setAccentColorIfPresentAndSupported(BrazeConfigurationProvider appConfigurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setAccentColorIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Set accent color for devices on Lollipop and above.
|
static void |
setCategoryIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Set category for devices on Lollipop and above.
|
static void |
setCategoryIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setContentIfPresent(BrazeConfigurationProvider configurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
Please use
setContentIfPresent(NotificationCompat.Builder, BrazeNotificationPayload) instead. |
static void |
setContentIfPresent(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Sets notification content if it exists in the payload.
|
static void |
setContentIntentIfPresent(android.content.Context context,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Create broadcast intent that will fire when the notification has been opened.
|
static void |
setDeleteIntent(android.content.Context context,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras) |
static boolean |
setLargeIconIfPresentAndSupported(android.content.Context context,
BrazeConfigurationProvider appConfigurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static boolean |
setLargeIconIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Set large icon.
|
static void |
setNotificationBadgeNumberIfPresent(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Sets the notification number, set via
NotificationCompat.Builder#setNumber(int) . |
static void |
setNotificationBadgeNumberIfPresent(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setNotificationChannelIfSupported(android.content.Context context,
BrazeConfigurationProvider appConfigurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
The channel id should be set in
NotificationCompat.Builder#Builder(Context, String) |
static void |
setNotificationDurationAlarm(android.content.Context context,
java.lang.Class<?> thisClass,
int notificationId,
int durationInMillis)
Creates an alarm which will issue a broadcast to cancel the notification specified by the given notificationId after the given duration.
|
static void |
setPriorityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Sets the priority of the notification if a priority is present in the notification extras.
|
static void |
setPublicVersionIfPresentAndSupported(android.content.Context context,
BrazeConfigurationProvider configurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setPublicVersionIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Set the public version of the notification for notifications with private visibility.
|
static void |
setSetShowWhen(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
This method exists to disable
NotificationCompat.Builder#setShowWhen(boolean)
for push stories. |
static void |
setSetShowWhen(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static int |
setSmallIcon(BrazeConfigurationProvider appConfigurationProvider,
NotificationCompat.Builder notificationBuilder)
Sets the icon used in the notification bar itself.
|
static void |
setSoundIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Notifications can optionally include a sound to play when the notification is delivered.
|
static void |
setSoundIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setStyleIfSupported(android.content.Context context,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras,
android.os.Bundle appboyExtras)
|
static void |
setSummaryTextIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Sets the subText of the notification if a summary is present in the notification extras.
|
static void |
setSummaryTextIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setTickerIfPresent(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Sets notification ticker to the title if it exists in the notificationExtras.
|
static void |
setTickerIfPresent(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static void |
setTitleIfPresent(BrazeConfigurationProvider configurationProvider,
NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
Please use
setTitleIfPresent(NotificationCompat.Builder, BrazeNotificationPayload) instead. |
static void |
setTitleIfPresent(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload) |
static void |
setVisibilityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
BrazeNotificationPayload payload)
Set visibility for devices on Lollipop and above.
|
static void |
setVisibilityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder,
android.os.Bundle notificationExtras)
Deprecated.
|
static boolean |
wakeScreenIfAppropriate(android.content.Context context,
BrazeConfigurationProvider configurationProvider,
android.os.Bundle notificationExtras)
This method will wake the device using a wake lock if the
Manifest.permission.WAKE_LOCK permission is present in the
manifest. |
@Deprecated public static final java.lang.String APPBOY_NOTIFICATION_OPENED_SUFFIX
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_OPENED
. Deprecated since 6/25/21@Deprecated public static final java.lang.String APPBOY_NOTIFICATION_RECEIVED_SUFFIX
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_OPENED
. Deprecated since 6/25/21@Deprecated public static final java.lang.String APPBOY_NOTIFICATION_DELETED_SUFFIX
Constants.BRAZE_PUSH_INTENT_NOTIFICATION_DELETED
. Deprecated since 6/25/21public static void handleNotificationOpened(android.content.Context context, android.content.Intent intent)
sendNotificationOpenedBroadcast(android.content.Context, android.content.Intent)
context
- Application contextintent
- the internal notification clicked intent constructed in
setContentIntentIfPresent(android.content.Context, NotificationCompat.Builder, android.os.Bundle)
public static void handleNotificationDeleted(android.content.Context context, android.content.Intent intent)
NotificationCompat.Builder#setDeleteIntent(PendingIntent)
context
- Application contextintent
- the internal notification delete intent constructed in
setDeleteIntent(Context, NotificationCompat.Builder, Bundle)
public static void routeUserWithNotificationOpenedIntent(android.content.Context context, android.content.Intent intent)
context
- intent
- the internal notification clicked intent constructed in
setContentIntentIfPresent(android.content.Context, NotificationCompat.Builder, android.os.Bundle)
@Deprecated public static android.os.Bundle getAppboyExtrasWithoutPreprocessing(android.os.Bundle notificationExtras)
BrazeNotificationPayload.getAttachedAppboyExtras(Bundle)
@Deprecated public static android.os.Bundle parseJSONStringDictionaryIntoBundle(java.lang.String jsonStringDictionary)
JsonUtils.parseJsonObjectIntoBundle(String)
public static boolean isAppboyPushMessage(android.content.Intent intent)
public static boolean isNotificationMessage(android.content.Intent intent)
public static void sendPushMessageReceivedBroadcast(android.content.Context context, android.os.Bundle notificationExtras)
public static boolean requestGeofenceRefreshIfAppropriate(android.content.Context context, android.os.Bundle notificationExtras)
context
- notificationExtras
- Notification extras as provided by FCM/ADM.public static void setNotificationDurationAlarm(android.content.Context context, java.lang.Class<?> thisClass, int notificationId, int durationInMillis)
@Deprecated public static int getNotificationId(android.os.Bundle notificationExtras)
getNotificationId(BrazeNotificationPayload)
public static int getNotificationId(BrazeNotificationPayload payload)
public static int getNotificationPriority(android.os.Bundle notificationExtras)
Starting with Android O, priority is set on a notification channel and not individually on notifications.
public static boolean wakeScreenIfAppropriate(android.content.Context context, BrazeConfigurationProvider configurationProvider, android.os.Bundle notificationExtras)
Manifest.permission.WAKE_LOCK
permission is present in the
manifest. If the permission is not present, this does nothing. If the screen is already on,
and the permission is present, this does nothing. If the priority of the incoming notification
is min, this does nothing.public static IBrazeNotificationFactory getActiveNotificationFactory()
public static void prefetchBitmapsIfNewlyReceivedStoryPush(android.content.Context context, android.os.Bundle notificationExtras, android.os.Bundle appboyExtras)
context
- Application context.notificationExtras
- Notification extras as provided by FCM/ADM.appboyExtras
- Bundle object containing 'extra' key value pairs defined by the client.@Deprecated public static void setTitleIfPresent(BrazeConfigurationProvider configurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setTitleIfPresent(NotificationCompat.Builder, BrazeNotificationPayload)
instead.public static void setTitleIfPresent(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setContentIfPresent(BrazeConfigurationProvider configurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setContentIfPresent(NotificationCompat.Builder, BrazeNotificationPayload)
instead.public static void setContentIfPresent(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setTickerIfPresent(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setTickerIfPresent(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setTickerIfPresent(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
public static void setContentIntentIfPresent(android.content.Context context, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
context
- notificationBuilder
- notificationExtras
- public static void setDeleteIntent(android.content.Context context, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
public static int setSmallIcon(BrazeConfigurationProvider appConfigurationProvider, NotificationCompat.Builder notificationBuilder)
@Deprecated public static void setSetShowWhen(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setSetShowWhen(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setSetShowWhen(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
NotificationCompat.Builder#setShowWhen(boolean)
for push stories.@Deprecated public static boolean setLargeIconIfPresentAndSupported(android.content.Context context, BrazeConfigurationProvider appConfigurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setLargeIconIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static boolean setLargeIconIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setSoundIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setSoundIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setSoundIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setSummaryTextIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setSummaryTextIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setSummaryTextIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
public static void setPriorityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
@Deprecated public static void setStyleIfSupported(android.content.Context context, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras, android.os.Bundle appboyExtras)
@Deprecated public static void setAccentColorIfPresentAndSupported(BrazeConfigurationProvider appConfigurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setAccentColorIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setAccentColorIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setCategoryIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setCategoryIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setCategoryIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setVisibilityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setVisibilityIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setVisibilityIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
@Deprecated public static void setPublicVersionIfPresentAndSupported(android.content.Context context, BrazeConfigurationProvider configurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setPublicVersionIfPresentAndSupported(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setPublicVersionIfPresentAndSupported(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
public static boolean isValidNotificationVisibility(int visibility)
public static void logBaiduNotificationClick(android.content.Context context, java.lang.String customContentString)
customContentString
- extra key value pairs in JSON format.public static void handleCancelNotificationAction(android.content.Context context, android.content.Intent intent)
context
- intent
- the cancel notification intentpublic static void cancelNotification(android.content.Context context, int notificationId)
handleCancelNotificationAction(android.content.Context, android.content.Intent)
context
- notificationId
- public static java.lang.Class<?> getNotificationReceiverClass()
public static boolean isUninstallTrackingPush(android.os.Bundle notificationExtras)
notificationExtras
- A notificationExtras bundle that is passed with the push received intent when a GCM/ADM message is
received, and that Braze passes in the intent to registered receivers.@Deprecated public static void setNotificationChannelIfSupported(android.content.Context context, BrazeConfigurationProvider appConfigurationProvider, NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
NotificationCompat.Builder#Builder(Context, String)
To change the default notification channel name and description, please use BrazeConfig.Builder#setDefaultNotificationChannelName(String)
and
BrazeConfig.Builder#setDefaultNotificationChannelDescription(String)
.
The default notification channel uses the id Constants.APPBOY_PUSH_DEFAULT_NOTIFICATION_CHANNEL_ID
.
public static java.lang.String getOrCreateNotificationChannelId(BrazeNotificationPayload payload)
NotificationChannel
, creating one if necessary.
Constants.APPBOY_PUSH_NOTIFICATION_CHANNEL_ID_KEY
key is present in
notificationExtras's and is the id of a valid NotificationChannel, this id will
be returned.Constants.APPBOY_PUSH_DEFAULT_NOTIFICATION_CHANNEL_ID
exists,
then Constants.APPBOY_PUSH_DEFAULT_NOTIFICATION_CHANNEL_ID
will be returned.Constants.APPBOY_PUSH_DEFAULT_NOTIFICATION_CHANNEL_ID
will be created and Constants.APPBOY_PUSH_DEFAULT_NOTIFICATION_CHANNEL_ID
will be
returned.@Deprecated public static java.lang.String getOrCreateNotificationChannelId(android.content.Context context, BrazeConfigurationProvider appConfigurationProvider, android.os.Bundle notificationExtras)
getOrCreateNotificationChannelId(BrazeNotificationPayload)
@Deprecated public static void setNotificationBadgeNumberIfPresent(NotificationCompat.Builder notificationBuilder, android.os.Bundle notificationExtras)
setNotificationBadgeNumberIfPresent(NotificationCompat.Builder, BrazeNotificationPayload)
public static void setNotificationBadgeNumberIfPresent(NotificationCompat.Builder notificationBuilder, BrazeNotificationPayload payload)
NotificationCompat.Builder#setNumber(int)
.
On Android O, this number is used with notification badges.public static void handlePushStoryPageClicked(android.content.Context context, android.content.Intent intent)
context
- Application context.intent
- The push story click intent.public static void handleContentCardsSerializedCardIfPresent(BrazeNotificationPayload payload)
public static boolean isInAppMessageTestPush(android.content.Intent intent)
Intent
contains extras found in a test push for in-app messages.Intent
is from an in-app message test send.