-
public final class Batch.PushBatch Push module
-
-
Method Summary
Modifier and Type Method Description static voidsetGCMSenderId(String gcmSenderId)Set the FCM/GCM Sender Id. static voidsetSmallIconResourceId(@DrawableRes() int resourceId)Set a custom small icon resource that push notifications will use. static voidsetSound(Uri uri)Set a custom sound uri that push notifications will use. static voidsetLargeIcon(Bitmap largeIcon)Set a custom large icon that push notifications will use. static BatchNotificationChannelsManagergetChannelsManager()Get the channels manager, allowing you to tweak how notifications will behave regardingthe channels feature introduced in Android 8. static voiddismissNotifications()Dismiss all notifications shown by the application. static EnumSet<PushNotificationType>getNotificationsType(Context context)Get the enabled notification typesMatches what you've set in setNotificationsType. static voidsetNotificationsType(EnumSet<PushNotificationType> types)Adjust the way Batch will display notifications. static booleanisBatchPush(Intent intent)Check if the received push is a Batch one. static booleanisBatchPush(RemoteMessage message)Check if the received push is a Batch one. static voidsetNotificationsColor(int argbColor)Set the notification accent color for Lollipop or later. static booleanisManualDisplayModeActivated()Get manual display mode for push notifications. static voidsetManualDisplay(boolean manualDisplay)Set manual display mode for push notifications. static voidappendBatchData(Intent pushIntent, Intent openIntent)Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings. static voidappendBatchData(@NonNull() Bundle pushIntentExtras, @NonNull() Intent openIntent)Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings. static voidappendBatchData(@NonNull() RemoteMessage remoteMessage, @NonNull() Intent openIntent)Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings. static PendingIntentmakePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given Intent. static PendingIntentmakePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() RemoteMessage remoteMessage)Make a PendingIntent suitable for notifications from a given Intent. static PendingIntentmakePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given deeplink. static PendingIntentmakePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() RemoteMessage remoteMessage)Make a PendingIntent suitable for notifications from a given deeplink. static booleanshouldDisplayPush(Context context, Intent intent)Should the developer handle and display this push, or will Batch display it? static booleanshouldDisplayPush(Context context, RemoteMessage remoteMessage)Should the developer handle and display this push, or will Batch display it? static voiddisplayNotification(Context context, Intent intent)Call this method to display the notification for this intent. static voiddisplayNotification(Context context, Intent intent, boolean bypassManualMode)Call this method to display the notification for this intent. static voiddisplayNotification(@NonNull() Context context, @NonNull() Intent intent, @Nullable() BatchNotificationInterceptor interceptor)Call this method to display the notification for this intent. static voiddisplayNotification(@NonNull() Context context, @NonNull() Intent intent, @Nullable() BatchNotificationInterceptor interceptor, boolean bypassManualMode)Call this method to display the notification for this intent. static voiddisplayNotification(Context context, RemoteMessage remoteMessage)Call this method to display the notification for this message. static voiddisplayNotification(@NonNull() Context context, @NonNull() RemoteMessage remoteMessage, @Nullable() BatchNotificationInterceptor interceptor)Call this method to display the notification for this message. static voidsetAdditionalIntentFlags(Integer flags)Sets additional intent flags for notifications.Doesn't work for external deeplinks. static voidonNotificationDisplayed(Context context, Intent intent)Call this method when you just displayed a Batch push notification by yourself. static voidonNotificationDisplayed(Context context, RemoteMessage remoteMessage)Call this method when you just displayed a Batch push notification by yourself. static StringgetLastKnownPushToken()Get the last known push token.The returned token might be outdated and invalid if this method is calledtoo early in your application lifecycle. static voidsetNotificationInterceptor(@Nullable() BatchNotificationInterceptor interceptor)Set a notification interceptor. static voidrefreshRegistration()Force Batch to renew the push token.You should not be calling this method unless we told you to. static voidrequestNotificationPermission(@NonNull() Context context)Request the notification runtime permission.Android 13 (API 33) introduced a new runtime permission for notifications called POST_NOTIFICATIONS.Without this permission, apps on Android 13 cannot show notifications.This method does nothing on Android 12 and lower, or if your application does not target API 33 or higher. -
-
Method Detail
-
setGCMSenderId
@Deprecated() static void setGCMSenderId(String gcmSenderId)
Set the FCM/GCM Sender Id. You can find more info on how to create it in our documentation.
- Parameters:
gcmSenderId- Google API sender ID (for example: 670330094152)
-
setSmallIconResourceId
static void setSmallIconResourceId(@DrawableRes() int resourceId)
Set a custom small icon resource that push notifications will use.
- Parameters:
resourceId- id of the resource (for example : R.drawable.
-
setSound
static void setSound(Uri uri)
Set a custom sound uri that push notifications will use.On Android 8.0, this setting will be applied to the default android.app.NotificationChannel thatBatch registers, meaning that you won't be able to change it after the first notification.If you use your own channel, this method will have no effect.
- Parameters:
uri- uri of the resource (see Notification.Builder.setSound for more details)null if you want to use the default notification sound
-
setLargeIcon
static void setLargeIcon(Bitmap largeIcon)
Set a custom large icon that push notifications will use.
- Parameters:
largeIcon- bitmap of the large icon
-
getChannelsManager
static BatchNotificationChannelsManager getChannelsManager()
Get the channels manager, allowing you to tweak how notifications will behave regardingthe channels feature introduced in Android 8.0 (API 26)
-
dismissNotifications
static void dismissNotifications()
Dismiss all notifications shown by the application.You should call this method after ) NB : This method will dismiss even not Batch notifications, this is a convenience method that you may not use if you have other notifications in your app.
-
getNotificationsType
static EnumSet<PushNotificationType> getNotificationsType(Context context)
Get the enabled notification typesMatches what you've set in setNotificationsType.
-
setNotificationsType
static void setNotificationsType(EnumSet<PushNotificationType> types)
Adjust the way Batch will display notifications.You should use this method if you want to remove vibration, light, sound or avoid notifications for this user.
Note: On Android 8.0 and higher, this method ignores LIGHTS, VIBRATE and SOUND.Only ALERT will be honored, toggling whether notifications should be displayed or not.This is because Android 8 manages notifications using channels, meaning that these settings cannot be in your app anymore, and must redirect to the system's UI.Use getChannelsManager to manage your channels.
- Parameters:
types- Type of notifications you want, default = ALERT + LIGHTS + VIBRATE + SOUND
-
isBatchPush
static boolean isBatchPush(Intent intent)
Check if the received push is a Batch one. If you have a custom push implementation into your app you shouldcall this method before doing anything else into the onReceive method.If it returns true, you should not handle the push.
-
isBatchPush
static boolean isBatchPush(RemoteMessage message)
Check if the received push is a Batch one. If you have a custom push implementation into your app you shouldcall this method before doing anything else.If it returns true, you should not handle the push.
- Parameters:
message- Firebase RemoteMessage
-
setNotificationsColor
static void setNotificationsColor(int argbColor)
Set the notification accent color for Lollipop or later.See Notification.color for more details
- Parameters:
argbColor- an ARGB integer like the constants in Color
-
isManualDisplayModeActivated
static boolean isManualDisplayModeActivated()
Get manual display mode for push notifications.
-
setManualDisplay
static void setManualDisplay(boolean manualDisplay)
Set manual display mode for push notifications. If you set manual display mode to true, no notifications will be shown automatically and you'll have to display it by yourself.
-
appendBatchData
static void appendBatchData(Intent pushIntent, Intent openIntent)
Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings.
- Parameters:
pushIntent- the intent from GCM/FCM, that originated this pushopenIntent- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
static void appendBatchData(@NonNull() Bundle pushIntentExtras, @NonNull() Intent openIntent)
Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings.
- Parameters:
pushIntentExtras- the extras of the intent coming from GCM/FCM, that originated this pushopenIntent- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
static void appendBatchData(@NonNull() RemoteMessage remoteMessage, @NonNull() Intent openIntent)
Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.It also powers other features, such as but not limited to mobile landings.
- Parameters:
remoteMessage- the FCM message contentopenIntent- the intent of the notification the will be triggered when the user clicks on it
-
makePendingIntent
@NonNull() static PendingIntent makePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() Bundle pushIntentExtras)
Make a PendingIntent suitable for notifications from a given Intent.This is useful for custom receivers, or BatchNotificationInterceptor implementations.
Warning: it will override the intent's action with a unique name, to ensure that existing notifications are not updated with this PendingIntent's content.If you rely on a custom action, you will have to make your own PendingIntent.
- Parameters:
context- Context.intent- The intent you want to be triggered when performing the pending intent.pushIntentExtras- Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings.
-
makePendingIntent
@NonNull() static PendingIntent makePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given Intent.This is useful for custom receivers, or BatchNotificationInterceptor implementations.
Warning: it will override the intent's action with a unique name, to ensure that existing notifications are not updated with this PendingIntent's content.If you rely on a custom action, you will have to make your own PendingIntent.
- Parameters:
context- Context.intent- The intent you want to be triggered when performing the pending intent.remoteMessage- Raw Firebase message, used to copy data used by Batch to power features such as direct opens, or mobile landings.
-
makePendingIntentForDeeplink
@Nullable() static PendingIntent makePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() Bundle pushIntentExtras)
Make a PendingIntent suitable for notifications from a given deeplink. It will use Batch's builtin action activity.
This is useful for custom receivers, or BatchNotificationInterceptor implementations.
- Parameters:
context- Context.deeplink- Deeplink string.pushIntentExtras- Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings.
-
makePendingIntentForDeeplink
@Nullable() static PendingIntent makePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given deeplink. It will use Batch's builtin action activity.
This is useful for custom receivers, or BatchNotificationInterceptor implementations.
- Parameters:
context- Context.deeplink- Deeplink string.remoteMessage- Raw Firebase message content, used to copy data used by Batch to power features such as direct opens, or mobile landings.
-
shouldDisplayPush
static boolean shouldDisplayPush(Context context, Intent intent)
Should the developer handle and display this push, or will Batch display it?Use this method to know if Batch will ignore this push, and that displaying it is your responsibility
-
shouldDisplayPush
static boolean shouldDisplayPush(Context context, RemoteMessage remoteMessage)
Should the developer handle and display this push, or will Batch display it?Use this method to know if Batch will ignore this push, and that displaying it is your responsibility
- Parameters:
remoteMessage- The Firebase message
-
displayNotification
static void displayNotification(Context context, Intent intent)
Call this method to display the notification for this intent.
-
displayNotification
static void displayNotification(Context context, Intent intent, boolean bypassManualMode)
Call this method to display the notification for this intent.
- Parameters:
bypassManualMode- If true, This method will ignore the manual mode value and always display the notification
-
displayNotification
static void displayNotification(@NonNull() Context context, @NonNull() Intent intent, @Nullable() BatchNotificationInterceptor interceptor)
Call this method to display the notification for this intent.Allows an interceptor to be set for this call, overriding the global one set using setNotificationInterceptor
-
displayNotification
static void displayNotification(@NonNull() Context context, @NonNull() Intent intent, @Nullable() BatchNotificationInterceptor interceptor, boolean bypassManualMode)
Call this method to display the notification for this intent.Allows an interceptor to be set for this call, overriding the global one set using setNotificationInterceptor
- Parameters:
bypassManualMode- If true, This method will ignore the manual mode value and always display the notification
-
displayNotification
static void displayNotification(Context context, RemoteMessage remoteMessage)
Call this method to display the notification for this message.
-
displayNotification
static void displayNotification(@NonNull() Context context, @NonNull() RemoteMessage remoteMessage, @Nullable() BatchNotificationInterceptor interceptor)
Call this method to display the notification for this message.Allows an interceptor to be set for this call, overriding the global one set using setNotificationInterceptor
-
setAdditionalIntentFlags
static void setAdditionalIntentFlags(Integer flags)
Sets additional intent flags for notifications.Doesn't work for external deeplinks.
- Parameters:
flags- Additional flags.
-
onNotificationDisplayed
static void onNotificationDisplayed(Context context, Intent intent)
Call this method when you just displayed a Batch push notification by yourself.
- Parameters:
intent- the gcm push intent
-
onNotificationDisplayed
static void onNotificationDisplayed(Context context, RemoteMessage remoteMessage)
Call this method when you just displayed a Batch push notification by yourself.
- Parameters:
remoteMessage- The Firebase message
-
getLastKnownPushToken
static String getLastKnownPushToken()
Get the last known push token.The returned token might be outdated and invalid if this method is calledtoo early in your application lifecycle.
Batch MUST be started in order to use this method.
-
setNotificationInterceptor
static void setNotificationInterceptor(@Nullable() BatchNotificationInterceptor interceptor)
Set a notification interceptor. It allows you to tweak various parts of a notification that Batch generates before displaying it.
- Parameters:
interceptor- A BatchNotificationInterceptor subclass.
-
refreshRegistration
static void refreshRegistration()
Force Batch to renew the push token.You should not be calling this method unless we told you to.
-
requestNotificationPermission
static void requestNotificationPermission(@NonNull() Context context)
Request the notification runtime permission.Android 13 (API 33) introduced a new runtime permission for notifications called POST_NOTIFICATIONS.Without this permission, apps on Android 13 cannot show notifications.This method does nothing on Android 12 and lower, or if your application does not target API 33 or higher.
- Parameters:
context- requesting the permission
-
-
-
-