-
public class PushModule extends BatchModule
Push Module of Batch
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringTAGpublic final static intNO_COLORprivate StringgcmSenderIdprivate intnotificationColorprivate booleanmanualDisplayprivate BatchNotificationInterceptornotificationInterceptor
-
Method Summary
Modifier and Type Method Description voidsetGCMSenderId(String senderId)Set the GCM sender id intgetNotificationColor()Get the notification color set by the developer voidsetManualDisplay(boolean manualDisplay)Set manual display mode for push notifications. BatchNotificationInterceptorgetNotificationInterceptor()Set the developer registered notification interceptor voidsetNotificationInterceptor(BatchNotificationInterceptor interceptor)Get the developer registered notification interceptor static PushModuleprovide()intgetCustomSmallIconResourceId()Return the custom small icon resource if any. voidsetCustomSmallIconResourceId(int resourceId)Set the custom small icon resource id. IntegergetAdditionalIntentFlags()User set additional intent flags for notifications.Can be null. voidsetAdditionalIntentFlags(Integer flags)Sets additional intent flags for notifications.Doesn't work for external deeplinks. BitmapgetCustomLargeIcon()Return the custom large icon if any. voidsetCustomLargeIcon(Bitmap largeIcon)Set the custom large icon. voiddismissNotifications()Dismiss all app notifications booleanisBatchPush(Intent intent)Check if the received push is a Batch one. booleanisBatchPush(RemoteMessage message)Firebase variant StringgetRegistrationID()Return the push token if available RegistrationgetRegistration(@NonNull() Context context)Get the persisted registration EnumSet<PushNotificationType>getNotificationsType(Context context)Get the enabled notification typesMatches what you've set in setNotificationsType. voidsetNotificationsType(EnumSet<PushNotificationType> types)Adjust the way Batch will display notifications. voidsetNotificationsColor(int argbColor)Set the notification accent color for Lollipop or later. voidsetSound(Uri soundUri)Override the default notification sound uriSee Notification.Builder.setSound for more details UrigetSound()Get the notification sound uri set by the developer booleanisManualDisplayModeActivated()Is manual display mode activated by the developer 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. voidappendBatchData(Bundle pushIntentExtras, 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. voidappendBatchData(@NonNull() RemoteMessage remoteMessage, Intent openIntent)Firebase variant of the method PendingIntentmakePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given Intent. PendingIntentmakePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() RemoteMessage message)Firebase variant of the method PendingIntentmakePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given deeplink. PendingIntentmakePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() RemoteMessage message)Firebase version of the original method booleanshouldDisplayPush(Context context, Intent intent)Should the developer handle and display this push booleanshouldDisplayPush(Context context, RemoteMessage message)Firebase variant voiddisplayNotification(Context context, Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)Call this method to display the notification for this intent. voiddisplayNotification(Context context, RemoteMessage message, BatchNotificationInterceptor interceptor)Call this method to display the notification for Firebase message voidonNotificationDisplayed(Context context, Intent intent)Call this method when you just displayed a Batch push notification by yourself. voidonNotificationDisplayed(Context context, RemoteMessage message)Firebase variant voidrefreshRegistration()Should be called when push token is updated in backgroundEx: onTokenRefresh() in a InstanceIDListenerServiceEx: onNewToken() in a HsmMessagingService AdsIdentifierProvidergetAdsIdentifierProvider()Get the ads identifier provider associated with the current registration provider static booleanisBatchPushServiceAvailable()Check if the Push Service is available static booleanisBackgroundRestricted(@NonNull() Context context)Check if is the app has been restricted by the user.Only available on Android P and forward. voidrequestNotificationPermission(@NonNull() Context context)Request the notification runtime permissionRequired for Android 13 (api 33)Do nothing if app target is lower than 13 StringgetId()ID of the module intgetState()Should return the state of the module (usually 0 for deactivated, 1 for activated) voidbatchWillStart()Called by Batch before batch startNB : Context & activity are already available from the runtimeManager -
-
Method Detail
-
setGCMSenderId
void setGCMSenderId(String senderId)
Set the GCM sender id
-
getNotificationColor
int getNotificationColor()
Get the notification color set by the developer
-
setManualDisplay
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.
-
getNotificationInterceptor
BatchNotificationInterceptor getNotificationInterceptor()
Set the developer registered notification interceptor
-
setNotificationInterceptor
void setNotificationInterceptor(BatchNotificationInterceptor interceptor)
Get the developer registered notification interceptor
-
provide
static PushModule provide()
-
getCustomSmallIconResourceId
int getCustomSmallIconResourceId()
Return the custom small icon resource if any.
-
setCustomSmallIconResourceId
void setCustomSmallIconResourceId(int resourceId)
Set the custom small icon resource id.
-
getAdditionalIntentFlags
Integer getAdditionalIntentFlags()
User set additional intent flags for notifications.Can be null.
-
setAdditionalIntentFlags
void setAdditionalIntentFlags(Integer flags)
Sets additional intent flags for notifications.Doesn't work for external deeplinks.
- Parameters:
flags- Additional flags.
-
getCustomLargeIcon
Bitmap getCustomLargeIcon()
Return the custom large icon if any.
-
setCustomLargeIcon
void setCustomLargeIcon(Bitmap largeIcon)
Set the custom large icon.
-
dismissNotifications
void dismissNotifications()
Dismiss all app notifications
-
isBatchPush
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
boolean isBatchPush(RemoteMessage message)
Firebase variant
-
getRegistrationID
String getRegistrationID()
Return the push token if available
-
getRegistration
Registration getRegistration(@NonNull() Context context)
Get the persisted registration
-
getNotificationsType
EnumSet<PushNotificationType> getNotificationsType(Context context)
Get the enabled notification typesMatches what you've set in setNotificationsType.
-
setNotificationsType
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.
- Parameters:
types- Type of notifications you want, default = ALERT + LIGHTS + VIBRATE + SOUND
-
setNotificationsColor
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
-
setSound
void setSound(Uri soundUri)
Override the default notification sound uriSee Notification.Builder.setSound for more details
- Parameters:
soundUri- Sound uri to set on notifications.
-
isManualDisplayModeActivated
boolean isManualDisplayModeActivated()
Is manual display mode activated by the developer
-
appendBatchData
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, that origined this pushopenIntent- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
void appendBatchData(Bundle pushIntentExtras, 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 intent extras from GCM, that origined this pushopenIntent- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
void appendBatchData(@NonNull() RemoteMessage remoteMessage, Intent openIntent)
Firebase variant of the method
-
makePendingIntent
@NonNull() 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:
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() PendingIntent makePendingIntent(@NonNull() Context context, @NonNull() Intent intent, @NonNull() RemoteMessage message)
Firebase variant of the method
-
makePendingIntentForDeeplink
@Nullable() 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, com.batch.android.BatchNotificationInterceptor or com.batch.android.BatchDeeplinkInterceptor implementations.
- Parameters:
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() PendingIntent makePendingIntentForDeeplink(@NonNull() Context context, @NonNull() String deeplink, @NonNull() RemoteMessage message)
Firebase version of the original method
-
shouldDisplayPush
boolean shouldDisplayPush(Context context, Intent intent)
Should the developer handle and display this push
- Parameters:
intent- the gcm push intent
-
shouldDisplayPush
boolean shouldDisplayPush(Context context, RemoteMessage message)
Firebase variant
-
displayNotification
void displayNotification(Context context, Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)
Call this method to display the notification for this intent.
- Parameters:
intent- the gcm push intent
-
displayNotification
void displayNotification(Context context, RemoteMessage message, BatchNotificationInterceptor interceptor)
Call this method to display the notification for Firebase message
-
onNotificationDisplayed
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
void onNotificationDisplayed(Context context, RemoteMessage message)
Firebase variant
-
refreshRegistration
void refreshRegistration()
Should be called when push token is updated in backgroundEx: onTokenRefresh() in a InstanceIDListenerServiceEx: onNewToken() in a HsmMessagingService
-
getAdsIdentifierProvider
AdsIdentifierProvider getAdsIdentifierProvider()
Get the ads identifier provider associated with the current registration provider
-
isBatchPushServiceAvailable
static boolean isBatchPushServiceAvailable()
Check if the Push Service is available
-
isBackgroundRestricted
static boolean isBackgroundRestricted(@NonNull() Context context)
Check if is the app has been restricted by the user.Only available on Android P and forward.
-
requestNotificationPermission
void requestNotificationPermission(@NonNull() Context context)
Request the notification runtime permissionRequired for Android 13 (api 33)Do nothing if app target is lower than 13
- Parameters:
context- requesting the permission
-
getState
int getState()
Should return the state of the module (usually 0 for deactivated, 1 for activated)
-
batchWillStart
void batchWillStart()
Called by Batch before batch startNB : Context & activity are already available from the runtimeManager
-
-
-
-