Class Batch.Messaging
- java.lang.Object
-
- com.batch.android.Batch.Messaging
-
- Enclosing class:
- Batch
public static final class Batch.Messaging extends java.lang.ObjectBatch Messaging module
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBatch.Messaging.DisplayHintstatic interfaceBatch.Messaging.DisplayHintProviderstatic interfaceBatch.Messaging.LifecycleListenerListener interface for messaging views lifecycle events.static interfaceBatch.Messaging.LifecycleListener2Listener interface for messaging events.
-
Field Summary
Fields Modifier and Type Field Description static intGLOBAL_TAP_ACTION_INDEXCTA Index representing a global tap action
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanhasPendingMessage()Check if Batch currently has a pending message, without forgetting it.static booleanisDoNotDisturbEnabled()Check if Batch Messaging is currently in Do Not Disturb modestatic BatchBannerViewloadBanner(android.content.Context context, BatchMessage message)Load theBatchBannerViewcorresponding to the message payload.static androidx.fragment.app.DialogFragmentloadFragment(android.content.Context context, BatchMessage message)Load theFragmentcorresponding to the message payload.static BatchMessagepopPendingMessage()Gets the currently enqueued message.static voidsetAutomaticMode(boolean automatic)Toggle this module's automatic mode.static voidsetDoNotDisturbEnabled(boolean enableDnd)Toggles whether Batch.Messaging should entier its "do not disturb" (DnD) mode, or exit it.static voidsetLifecycleListener(Batch.Messaging.LifecycleListener listener)Set a lifecycle listener.static voidsetShowForegroundLandings(boolean showForegroundLandings)Toggle whether mobile landings should be shown directly rather than displaying a notification when the app is in foreground.static voidsetTypefaceOverride(android.graphics.Typeface normalTypeface, android.graphics.Typeface boldTypeface)Override theTypeface(aka font) used by Batch's messaging views.static voidshow(android.content.Context context, BatchMessage message)Asynchronously show theBatchMessage.
-
-
-
Field Detail
-
GLOBAL_TAP_ACTION_INDEX
public static final int GLOBAL_TAP_ACTION_INDEX
CTA Index representing a global tap action- See Also:
- Constant Field Values
-
-
Method Detail
-
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 true.
- 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(Context, BatchMessage)- Parameters:
automatic- True to enable the automatic mode, false to disable it.
-
setTypefaceOverride
public static void setTypefaceOverride(@Nullable android.graphics.Typeface normalTypeface, @Nullable android.graphics.Typeface boldTypeface)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
public static void setLifecycleListener(@Nullable Batch.Messaging.LifecycleListener listener)Set a lifecycle listener. For more information about what a lifecycle listener is useful for, look atBatch.Messaging.LifecycleListener's documentation.- Parameters:
listener- ABatch.Messaging.LifecycleListenerimplementation. null to remove a previously set one.
-
loadFragment
@NonNull public static androidx.fragment.app.DialogFragment loadFragment(@NonNull android.content.Context context, @NonNull BatchMessage message) throws BatchMessagingExceptionLoad theFragmentcorresponding 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(Context, 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:
java.lang.IllegalArgumentExceptionBatchMessagingException
-
loadBanner
@NonNull public static BatchBannerView loadBanner(@NonNull android.content.Context context, @NonNull BatchMessage message) throws BatchMessagingException
Load theBatchBannerViewcorresponding to the message payload.
This method should be called from your UI thread.If the message does not contain a banner, a
BatchMessagingExceptionwill 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:
java.lang.IllegalArgumentExceptionBatchMessagingException
-
show
public static void show(@NonNull android.content.Context context, @NonNull BatchMessage message)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.DisplayHintProviderin 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
Batch.Messaging.LifecycleListener2implementation.- 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
@Nullable public static BatchMessage 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.
-
-