public class BrazeInAppMessageManager extends InAppMessageManagerBase
BrazeInAppMessageManager
will also keep track of in-app
impressions and clicks, which can be viewed on the dashboard.
When an in-app message is received from Braze, the
IInAppMessageManagerListener#onInAppMessageReceived(IInAppMessage)
method is called (if set). If this method returns true, that signals to the BrazeInAppMessageManager that
the in-app message will be handled by the host app and that it should not be displayed by the
BrazeInAppMessageManager. This method should be used if you choose to display the in-app message in a custom
way. If false is returned, the BrazeInAppMessageManager
attempts to display the in-app message.
If there is already an in-app message being displayed, the new in-app message will be put onto the top of the
stack and can be displayed at a later time. If there is no in-app message being displayed, then the
IInAppMessageManagerListener.beforeInAppMessageDisplayed(IInAppMessage)
will be called. The InAppMessageOperation
return value can be used to
control when the in-app message should be displayed. A suggested usage of this method would be to delay
in-app message messages in certain parts of the app by returning InAppMessageOperation.DISPLAY_LATER
when in-app message would be distracting to the users app experience. If the method returns
InAppMessageOperation.DISPLAY_NOW
then the in-app message will be displayed
immediately.
The IInAppMessageManagerListener.onInAppMessageClicked(IInAppMessage, InAppMessageCloser)
and IInAppMessageManagerListener.onInAppMessageDismissed(IInAppMessage)
methods can be used to override the default click and dismiss behavior.
By default, in-app messages fade in and out from view. The slideup type of in-app message slides in and out of view
can be dismissed by swiping the view horizontally. If the in-app message's DismissType is set to AUTO_DISMISS,
then the in-app message will animate out of view once the set duration time has elapsed.
In order to use a custom view, you must create a custom view factory using the
InAppMessageManagerBase.setCustomInAppMessageViewFactory(IInAppMessageViewFactory inAppMessageViewFactory)
method.
A new in-app message View
object is created when a in-app message is displayed and also
when the user navigates away to another Activity
. This happens so that the
Activity can be garbage collected and does not create a memory leak. For that reason, the
registerInAppMessageManager(android.app.Activity)
and unregisterInAppMessageManager(android.app.Activity)
must be called in the Activity.onResume()
and Activity.onPause()
methods of every Activity.Constructor and Description |
---|
BrazeInAppMessageManager() |
Modifier and Type | Method and Description |
---|---|
void |
addInAppMessage(IInAppMessage inAppMessage)
Provides a in-app message that will then be handled by the in-app message manager.
|
void |
displayInAppMessage(IInAppMessage inAppMessage,
boolean isCarryOver)
Internal method, do not call as part of an integration!
Attempts to display an IInAppMessage to the user. |
void |
ensureSubscribedToInAppMessageEvents(android.content.Context context)
Ensures the InAppMessageManager is subscribed in-app message events if not already subscribed.
|
IInAppMessage |
getCarryoverInAppMessage()
An In-App Message being carried over during the
unregisterInAppMessageManager(Activity)
registerInAppMessageManager(Activity) transition. |
java.util.Stack<IInAppMessage> |
getInAppMessageStack()
The stack of In-App Messages waiting to be displayed.
|
static BrazeInAppMessageManager |
getInstance() |
boolean |
getIsCurrentlyDisplayingInAppMessage()
Gets whether an in-app message is currently displaying on the device.
|
IInAppMessage |
getUnregisteredInAppMessage()
An In-App Message that could not display after a
call to
requestDisplayInAppMessage() due to no
Activity being registered via registerInAppMessageManager(Activity) |
void |
hideCurrentlyDisplayingInAppMessage(boolean dismissed)
Hides any currently displaying in-app message.
|
void |
registerInAppMessageManager(android.app.Activity activity)
Registers the in-app message manager, which will listen to and display incoming in-app messages.
|
boolean |
requestDisplayInAppMessage()
Asks the InAppMessageManager to display the next in-app message if one is not currently being displayed.
|
void |
resetAfterInAppMessageClose()
Resets the
BrazeInAppMessageManager to its original state before the last in-app message
was displayed. |
void |
unregisterInAppMessageManager(android.app.Activity activity)
Unregisters the in-app message manager.
|
getActivity, getApplicationContext, getControlInAppMessageManagerListener, getDefaultInAppMessageViewFactory, getDoesBackButtonDismissInAppMessageView, getDoesClickOutsideModalViewDismissInAppMessageView, getHtmlInAppMessageActionListener, getInAppMessageAnimationFactory, getInAppMessageManagerListener, getInAppMessageViewFactory, getInAppMessageViewWrapperFactory, setBackButtonDismissesInAppMessageView, setClickOutsideModalViewDismissInAppMessageView, setCustomControlInAppMessageManagerListener, setCustomHtmlInAppMessageActionListener, setCustomInAppMessageAnimationFactory, setCustomInAppMessageManagerListener, setCustomInAppMessageViewFactory, setCustomInAppMessageViewWrapperFactory
public static BrazeInAppMessageManager getInstance()
public void ensureSubscribedToInAppMessageEvents(android.content.Context context)
context
- The application contextpublic void registerInAppMessageManager(android.app.Activity activity)
ensureSubscribedToInAppMessageEvents(Context)
.
To be sure that no in-app messages are lost, you should call ensureSubscribedToInAppMessageEvents(Context)
as early
as possible in your app, preferably in your Application.onCreate()
.activity
- The current Activity.public void unregisterInAppMessageManager(android.app.Activity activity)
activity
- The current Activity.public void addInAppMessage(IInAppMessage inAppMessage)
inAppMessage
- The in-app message to add.public boolean requestDisplayInAppMessage()
public void hideCurrentlyDisplayingInAppMessage(boolean dismissed)
dismissed
- whether the message was dismissed by the user. If dismissed is true,
IInAppMessageViewLifecycleListener.onDismissed() will be called on the current
IInAppMessageViewLifecycleListener.public void resetAfterInAppMessageClose()
BrazeInAppMessageManager
to its original state before the last in-app message
was displayed. This allows for a new in-app message to be displayed after calling this method.
ViewUtils.setActivityRequestedOrientation(Activity, int)
is called with the original
orientation before the last in-app message was displayed.public boolean getIsCurrentlyDisplayingInAppMessage()
public java.util.Stack<IInAppMessage> getInAppMessageStack()
public IInAppMessage getCarryoverInAppMessage()
unregisterInAppMessageManager(Activity)
registerInAppMessageManager(Activity)
transition.public IInAppMessage getUnregisteredInAppMessage()
requestDisplayInAppMessage()
due to no
Activity
being registered via registerInAppMessageManager(Activity)
public void displayInAppMessage(IInAppMessage inAppMessage, boolean isCarryOver)
IInAppMessage
to the user.inAppMessage
- The IInAppMessage
.isCarryOver
- If this IInAppMessage
is "carried over" from an Activity
transition.