-
public final class Batch.MessagingBatch Messaging module
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceBatch.Messaging.LifecycleListenerListener interface for messaging views lifecycle events.Implement this if you want to be notified of what happens to the messaging view (for example, perform some analytics on show/hide).You're also required to implement this if you want to add actions with a "callback" type.
public interfaceBatch.Messaging.LifecycleListener2Listener interface for messaging events.If you'd like to opt-in to additional lifecycle events, you should implement this methods,as it gives you more control about how and when to display In-App Messages
public interfaceBatch.Messaging.DisplayHintProviderpublic classBatch.Messaging.DisplayHint
-
Field Summary
Fields Modifier and Type Field Description public final static intGLOBAL_TAP_ACTION_INDEX
-
Method Summary
Modifier and Type Method Description static voidsetShowForegroundLandings(boolean showForegroundLandings)Toggle whether mobile landings should be shown directly rather than displaying a notificationwhen the app is in foreground. static voidsetAutomaticMode(boolean automatic)Toggle this module's automatic mode. static voidsetTypefaceOverride(@Nullable() Typeface normalTypeface, @Nullable() Typeface boldTypeface)Override the Typeface (aka font) used by Batch's messaging views.You'll need to provide both the normal and bold typefaces. static voidsetLifecycleListener(@Nullable() Batch.Messaging.LifecycleListener listener)Set a lifecycle listener. static DialogFragmentloadFragment(@NonNull() Context context, @NonNull() BatchMessage message)Load the Fragment corresponding to the message payload. static BatchBannerViewloadBanner(@NonNull() Context context, @NonNull() BatchMessage message)Load the BatchBannerView corresponding to the message payload. static voidshow(@NonNull() Context context, @NonNull() BatchMessage message)Asynchronously show the BatchMessage. static voidsetDoNotDisturbEnabled(boolean enableDnd)Toggles whether Batch.Messaging should entier its "do not disturb" (DnD) mode, or exit it. static booleanisDoNotDisturbEnabled()Check if Batch Messaging is currently in Do Not Disturb mode static booleanhasPendingMessage()Check if Batch currently has a pending message, without forgetting it. static BatchMessagepopPendingMessage()Gets the currently enqueued message. -
-
Method Detail
-
setShowForegroundLandings
static void setShowForegroundLandings(boolean showForegroundLandings)
Toggle whether mobile landings should be shown directly rather than displaying a notificationwhen the app is in foreground.
Default is false.
- Parameters:
showForegroundLandings- True to enable show landings, false to display a notification like when the application is in the background.
-
setAutomaticMode
static void setAutomaticMode(boolean automatic)
Toggle this module's automatic mode. By default, this value is "true".
If you disable automatic mode, you will have to implement loadFragment
- Parameters:
automatic- True to enable the automatic mode, false to disable it.
-
setTypefaceOverride
static void setTypefaceOverride(@Nullable() Typeface normalTypeface, @Nullable() Typeface boldTypeface)
Override the Typeface (aka font) used by Batch's messaging views.You'll need to provide both the normal and bold typefaces. If you only provide one, the result might be inconsistent.
In order to revert to the system font, set the typefaces to null.
- Parameters:
normalTypeface- Typeface for normal text.boldTypeface- Typeface for bold text.
-
setLifecycleListener
static void setLifecycleListener(@Nullable() Batch.Messaging.LifecycleListener listener)
Set a lifecycle listener. For more information about what a lifecycle listener is useful for, look at LifecycleListener's documentation.
- Parameters:
listener- A LifecycleListener implementation.
-
loadFragment
@NonNull() static DialogFragment loadFragment(@NonNull() Context context, @NonNull() BatchMessage message)
Load the Fragment corresponding to the message payload.This method should be called from your UI thread.
If the specified message contains a banner, this method will throw a BatchMessagingException.You should then fallback on loadBanner, or attempt it before,as there is currently no way of checking whether a BatchMessage contains a banner, an interstitial,or any potential future format.
- Parameters:
context- Your activity's context.message- Message to display.
-
loadBanner
@NonNull() static BatchBannerView loadBanner(@NonNull() Context context, @NonNull() BatchMessage message)
Load the BatchBannerView corresponding to the message payload.This method should be called from your UI thread.
If the message does not contain a banner, a BatchMessagingException will be thrown.
- Parameters:
context- Your activity's context.message- Message to display.
-
show
static void show(@NonNull() Context context, @NonNull() BatchMessage message)
Asynchronously show the BatchMessage. It will be displayed in a dedicated activity (MessagingActivity).
Note that if this method will work even if Batch is in do not disturb mode.
The given context should be an Activity instance to enable support for the banner format, as ithas to be attached to an activity. If you want to tweak how the SDK displays a banner, you can implement Batch.Messaging.DisplayHintProvider in your activity.
- Parameters:
context- Your activity's context, Can't be null.message- Message to show.
-
setDoNotDisturbEnabled
static void setDoNotDisturbEnabled(boolean enableDnd)
Toggles whether Batch.Messaging should entier its "do not disturb" (DnD) mode, or exit it.
While in DnD, Batch will not display landings, not matter if they've been triggered by notifications or an In-App Campaign, even in automatic mode.
This mode is useful for times where you don't want Batch to interrupt your user, such as during a splashscreen, a video or an interstitial ad.
If a message should have been displayed during DnD, Batch will enqueue it, overwriting any previously enqueued message.When exiting DnD, Batch will not display the message automatically: you'll have to call the queue management methods to display the message, if you want to.See hasPendingMessage, popPendingMessage to manage the enqueued message, if any.
Note: This is only supported if automatic mode is disabled. Messages will not be enqueued, as they will be delivered to your LifecycleListener2 implementation.
- Parameters:
enableDnd- true to enable DnD, false to disable it
-
isDoNotDisturbEnabled
static boolean isDoNotDisturbEnabled()
Check if Batch Messaging is currently in Do Not Disturb mode
-
hasPendingMessage
static boolean hasPendingMessage()
Check if Batch currently has a pending message, without forgetting it.
-
popPendingMessage
@Nullable() static BatchMessage popPendingMessage()
Gets the currently enqueued message.
Note: Calling this removes the pending message from Batch's queue. Further calls to thismethod will return null, until another message gets enqueues.
-
-
-
-