Class Batch.Messaging
- Enclosing class:
- Batch
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
static interface
Listener interface for messaging views lifecycle events.static interface
Listener interface for messaging events. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
CTA Index representing a global tap action -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Check if Batch currently has a pending message, without forgetting it.static boolean
Check if Batch Messaging is currently in Do Not Disturb modestatic BatchBannerView
loadBanner
(Context context, BatchMessage message) Load theBatchBannerView
corresponding to the message payload.static androidx.fragment.app.DialogFragment
loadFragment
(Context context, BatchMessage message) Load theFragment
corresponding to the message payload.static BatchMessage
Gets the currently enqueued message.static void
setAutomaticMode
(boolean automatic) Toggle this module's automatic mode.static void
setDoNotDisturbEnabled
(boolean enableDnd) Toggles whether Batch.Messaging should entier its "do not disturb" (DnD) mode, or exit it.static void
Set a lifecycle listener.static void
setShowForegroundLandings
(boolean showForegroundLandings) Toggle whether mobile landings should be shown directly rather than displaying a notification when the app is in foreground.static void
setTypefaceOverride
(Typeface normalTypeface, Typeface boldTypeface) Override theTypeface
(aka font) used by Batch's messaging views.static void
show
(Context context, BatchMessage message) Asynchronously show theBatchMessage
.
-
Field Details
-
GLOBAL_TAP_ACTION_INDEX
public static final int GLOBAL_TAP_ACTION_INDEXCTA Index representing a global tap action- See Also:
-
-
Method Details
-
setShowForegroundLandings
public static void setShowForegroundLandings(boolean showForegroundLandings) Toggle whether mobile landings should be shown directly rather than displaying a notification when 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
public 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(android.content.Context,com.batch.android.BatchMessage)
- Parameters:
automatic
- True to enable the automatic mode, false to disable it.
-
setTypefaceOverride
Override theTypeface
(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
Set a lifecycle listener. For more information about what a lifecycle listener is useful for, look atLifecycleListener
's documentation.- Parameters:
listener
- ALifecycleListener
implementation. null to remove a previously set one.
-
loadFragment
public static androidx.fragment.app.DialogFragment loadFragment(Context context, BatchMessage message) throws BatchMessagingException Load theFragment
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 onloadBanner(android.content.Context,com.batch.android.BatchMessage)
, 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. Can't be null.message
- Message to display. Can't be null.- Throws:
IllegalArgumentException
- If some parameters are null.BatchMessagingException
- When loading fail
-
loadBanner
public static BatchBannerView loadBanner(Context context, BatchMessage message) throws BatchMessagingException Load theBatchBannerView
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. Can't be null.message
- Message to display. Can't be null.- Returns:
- A Banner instance.
- Throws:
IllegalArgumentException
- If some parameters are null.BatchMessagingException
- When loading fail
-
show
Asynchronously show theBatchMessage
. 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 it has 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. Can't be null.
-
setDoNotDisturbEnabled
public 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.
SeehasPendingMessage()
,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
public static boolean isDoNotDisturbEnabled()Check if Batch Messaging is currently in Do Not Disturb mode -
hasPendingMessage
public static boolean hasPendingMessage()Check if Batch currently has a pending message, without forgetting it.- Returns:
- true if a message is pending, false otherwise.
-
popPendingMessage
Gets the currently enqueued message.Note: Calling this removes the pending message from Batch's queue. Further calls to this method will return null, until another message gets enqueues.
- Returns:
- The enqueued message, if any.
-