Package com.batch.android.module
Class PushModule
- java.lang.Object
-
- com.batch.android.module.BatchModule
-
- com.batch.android.module.PushModule
-
public class PushModule extends BatchModule
Push Module of Batch
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendBatchData(android.content.Intent pushIntent, android.content.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.voidappendBatchData(android.os.Bundle pushIntentExtras, android.content.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.voidappendBatchData(com.google.firebase.messaging.RemoteMessage remoteMessage, android.content.Intent openIntent)Firebase variant of the methodvoidbatchWillStart()Called by Batch before batch start
NB : Context & activity are already available from the runtimeManagervoiddismissNotifications()Dismiss all app notificationsvoiddisplayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)Call this method to display the notification for this intent.voiddisplayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage message, BatchNotificationInterceptor interceptor)Call this method to display the notification for Firebase messagejava.lang.IntegergetAdditionalIntentFlags()User set additional intent flags for notifications.AdsIdentifierProvidergetAdsIdentifierProvider()Get the ads identifier provider associated with the current registration providerandroid.graphics.BitmapgetCustomLargeIcon()Return the custom large icon if any.intgetCustomSmallIconResourceId()Return the custom small icon resource if any.java.lang.StringgetId()ID of the moduleintgetNotificationColor()Get the notification color set by the developerBatchNotificationInterceptorgetNotificationInterceptor()Set the developer registered notification interceptorjava.util.EnumSet<PushNotificationType>getNotificationsType(android.content.Context context)Get the enabled notification types
Matches what you've set in setNotificationsType.RegistrationgetRegistration(android.content.Context context)Get the persisted registrationjava.lang.StringgetRegistrationID()Return the push token if availableandroid.net.UrigetSound()Get the notification sound uri set by the developerintgetState()Should return the state of the module (usually 0 for deactivated, 1 for activated)static booleanisBackgroundRestricted(android.content.Context context)Check if is the app has been restricted by the user.booleanisBatchPush(android.content.Intent intent)Check if the received push is a Batch one.booleanisBatchPush(com.google.firebase.messaging.RemoteMessage message)Firebase variantstatic booleanisBatchPushServiceAvailable()Check if the Push Service is availablebooleanisManualDisplayModeActivated()Is manual display mode activated by the developerandroid.app.PendingIntentmakePendingIntent(android.content.Context context, android.content.Intent intent, android.os.Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given Intent.android.app.PendingIntentmakePendingIntent(android.content.Context context, android.content.Intent intent, com.google.firebase.messaging.RemoteMessage message)Firebase variant of the methodandroid.app.PendingIntentmakePendingIntentForDeeplink(android.content.Context context, java.lang.String deeplink, android.os.Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given deeplink.android.app.PendingIntentmakePendingIntentForDeeplink(android.content.Context context, java.lang.String deeplink, com.google.firebase.messaging.RemoteMessage message)Firebase version of the original methodvoidonNotificationDisplayed(android.content.Context context, android.content.Intent intent)Call this method when you just displayed a Batch push notification by yourself.voidonNotificationDisplayed(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)Firebase variantstatic PushModuleprovide()voidrefreshRegistration()Should be called when push token is updated in background Ex: onTokenRefresh() in a InstanceIDListenerService Ex: onNewToken() in a HsmMessagingServicevoidsetAdditionalIntentFlags(java.lang.Integer flags)Sets additional intent flags for notifications.voidsetCustomLargeIcon(android.graphics.Bitmap largeIcon)Set the custom large icon.voidsetCustomSmallIconResourceId(int resourceId)Set the custom small icon resource id.voidsetGCMSenderId(java.lang.String senderId)Set the GCM sender idvoidsetManualDisplay(boolean manualDisplay)Set manual display mode for push notifications.voidsetNotificationInterceptor(BatchNotificationInterceptor interceptor)Get the developer registered notification interceptorvoidsetNotificationsColor(int argbColor)Set the notification accent color for Lollipop or later.voidsetNotificationsType(java.util.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.voidsetSound(android.net.Uri soundUri)Override the default notification sound uri See Notification.Builder.setSound for more detailsbooleanshouldDisplayPush(android.content.Context context, android.content.Intent intent)Should the developer handle and display this pushbooleanshouldDisplayPush(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)Firebase variant-
Methods inherited from class com.batch.android.module.BatchModule
batchDidStart, batchDidStop, batchIsFinishing, batchWillStop
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
NO_COLOR
public static final int NO_COLOR
Default value for no accent color set by the developer- See Also:
- Constant Field Values
-
-
Method Detail
-
provide
public static PushModule provide()
-
getCustomSmallIconResourceId
public int getCustomSmallIconResourceId()
Return the custom small icon resource if any.- Returns:
- resource id if any, 0 if not.
-
setCustomSmallIconResourceId
public void setCustomSmallIconResourceId(int resourceId)
Set the custom small icon resource id.- Parameters:
resourceId-
-
getAdditionalIntentFlags
public java.lang.Integer getAdditionalIntentFlags()
User set additional intent flags for notifications. Can be null.
-
setAdditionalIntentFlags
public void setAdditionalIntentFlags(java.lang.Integer flags)
Sets additional intent flags for notifications. Doesn't work for external deeplinks.- Parameters:
flags- Additional flags. "null" to clear.
-
getCustomLargeIcon
public android.graphics.Bitmap getCustomLargeIcon()
Return the custom large icon if any.- Returns:
- resource if any, null if not.
-
setCustomLargeIcon
public void setCustomLargeIcon(android.graphics.Bitmap largeIcon)
Set the custom large icon.- Parameters:
largeIcon-
-
setGCMSenderId
public void setGCMSenderId(java.lang.String senderId)
Set the GCM sender id- Parameters:
senderId-
-
setNotificationInterceptor
public void setNotificationInterceptor(BatchNotificationInterceptor interceptor)
Get the developer registered notification interceptor
-
getNotificationInterceptor
public BatchNotificationInterceptor getNotificationInterceptor()
Set the developer registered notification interceptor
-
dismissNotifications
public void dismissNotifications()
Dismiss all app notifications
-
isBatchPush
public boolean isBatchPush(android.content.Intent intent)
Check if the received push is a Batch one. If you have a custom push implementation into your app you should call this method before doing anything else into theBroadcastReceiver.onReceive(Context, Intent)method. If it returns true, you should not handle the push.- Parameters:
intent-- Returns:
- true if the push is for Batch and you shouldn't handle it, false otherwise
-
isBatchPush
public boolean isBatchPush(com.google.firebase.messaging.RemoteMessage message)
Firebase variant
-
getRegistrationID
public java.lang.String getRegistrationID()
Return the push token if available- Returns:
- token if available, null otherwise
-
getRegistration
public Registration getRegistration(@NonNull android.content.Context context)
Get the persisted registration
-
getNotificationsType
public java.util.EnumSet<PushNotificationType> getNotificationsType(android.content.Context context)
Get the enabled notification types
Matches what you've set in setNotificationsType.- Returns:
- Type of notifications you previously set. Be careful, as this can be null if you never used setNotificationsType() or if your context is invalid
-
setNotificationsType
public void setNotificationsType(java.util.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
public 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 inColor
-
getNotificationColor
public int getNotificationColor()
Get the notification color set by the developer- Returns:
- color if set,
NO_COLORif not
-
setSound
public void setSound(android.net.Uri soundUri)
Override the default notification sound uri See Notification.Builder.setSound for more details- Parameters:
soundUri- Sound uri to set on notifications. Null to use the default sound.
-
getSound
public android.net.Uri getSound()
Get the notification sound uri set by the developer- Returns:
- the uri override if set, null if not
-
setManualDisplay
public 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.- Parameters:
manualDisplay-
-
isManualDisplayModeActivated
public boolean isManualDisplayModeActivated()
Is manual display mode activated by the developer- Returns:
-
appendBatchData
public void appendBatchData(android.content.Intent pushIntent, android.content.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
public void appendBatchData(android.os.Bundle pushIntentExtras, android.content.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
public void appendBatchData(@NonNull com.google.firebase.messaging.RemoteMessage remoteMessage, android.content.Intent openIntent)Firebase variant of the method
-
makePendingIntent
@NonNull public android.app.PendingIntent makePendingIntent(@NonNull android.content.Context context, @NonNull android.content.Intent intent, @NonNull android.os.Bundle pushIntentExtras)Make a PendingIntent suitable for notifications from a given Intent. This is useful for custom receivers, orBatchNotificationInterceptorimplementations.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. Must be an intent compatible withPendingIntent.getActivity(Context, int, Intent, int). Cannot be null.pushIntentExtras- Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null.- Returns:
- A PendingIntent instance, wrapping the given Intent.
-
makePendingIntent
@NonNull public android.app.PendingIntent makePendingIntent(@NonNull android.content.Context context, @NonNull android.content.Intent intent, @NonNull com.google.firebase.messaging.RemoteMessage message)Firebase variant of the method
-
makePendingIntentForDeeplink
@Nullable public android.app.PendingIntent makePendingIntentForDeeplink(@NonNull android.content.Context context, @NonNull java.lang.String deeplink, @NonNull android.os.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,
BatchNotificationInterceptororBatchDeeplinkInterceptorimplementations.- Parameters:
deeplink- Deeplink string. Cannot be null.pushIntentExtras- Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null.- Returns:
- A PendingIntent set to open Batch's builtin action activity to open the specified deeplink. Can be null if the deeplink is not valid.
-
makePendingIntentForDeeplink
@Nullable public android.app.PendingIntent makePendingIntentForDeeplink(@NonNull android.content.Context context, @NonNull java.lang.String deeplink, @NonNull com.google.firebase.messaging.RemoteMessage message)Firebase version of the original method
-
shouldDisplayPush
public boolean shouldDisplayPush(android.content.Context context, android.content.Intent intent)Should the developer handle and display this push- Parameters:
context-intent- the gcm push intent- Returns:
- true if the push is valid and should be handled, false otherwise
-
shouldDisplayPush
public boolean shouldDisplayPush(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)Firebase variant
-
displayNotification
public void displayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)Call this method to display the notification for this intent.- Parameters:
context-intent- the gcm push intent
-
displayNotification
public void displayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage message, BatchNotificationInterceptor interceptor)Call this method to display the notification for Firebase message
-
onNotificationDisplayed
public void onNotificationDisplayed(android.content.Context context, android.content.Intent intent)Call this method when you just displayed a Batch push notification by yourself.- Parameters:
context-intent- the gcm push intent
-
onNotificationDisplayed
public void onNotificationDisplayed(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)Firebase variant
-
refreshRegistration
public void refreshRegistration()
Should be called when push token is updated in background Ex: onTokenRefresh() in a InstanceIDListenerService Ex: onNewToken() in a HsmMessagingService
-
getAdsIdentifierProvider
public AdsIdentifierProvider getAdsIdentifierProvider()
Get the ads identifier provider associated with the current registration provider- Returns:
-
isBatchPushServiceAvailable
public static boolean isBatchPushServiceAvailable()
Check if the Push Service is available- Returns:
-
isBackgroundRestricted
public static boolean isBackgroundRestricted(@NonNull android.content.Context context)Check if is the app has been restricted by the user. Only available on Android P and forward.- Parameters:
context-- Returns:
-
getId
public java.lang.String getId()
Description copied from class:BatchModuleID of the module- Specified by:
getIdin classBatchModule- Returns:
-
getState
public int getState()
Description copied from class:BatchModuleShould return the state of the module (usually 0 for deactivated, 1 for activated)- Specified by:
getStatein classBatchModule- Returns:
-
batchWillStart
public void batchWillStart()
Description copied from class:BatchModuleCalled by Batch before batch start
NB : Context & activity are already available from the runtimeManager- Overrides:
batchWillStartin classBatchModule
-
-