Mensagem no app
Saiba mais sobre mensagens no app e como configurá-las para o Braze SDK.
Prerequisites
Before you can use this feature, you’ll need to integrate the Android Braze SDK. You’ll also need to enable in-app messages.
Message types
Braze offers several default in-app message types, each customizable with messages, images, Font Awesome icons, click actions, analytics, color schemes, and more.
Their basic behavior and traits are defined by the IInAppMessage
interface, in a subclass called InAppMessageBase
. IInAppMessage
also includes a subinterface, IInAppMessageImmersive
, which lets you add close, click-action, and analytics buttons to your app.
Keep in mind, in-app messages containing buttons will include the clickAction
message in the final payload if the click action is added prior to adding the button text.
modal
in-app messages appear in the center of the screen and are framed by a translucent panel. Useful for more critical messaging, they can be equipped with two click-action and analytics-enabled buttons.
This message type is a subclass of InAppMessageImmersiveBase
, an abstract class that implements IInAppMessageImmersive
, giving you the option to add custom functionality to your locally generated in-app messages.
full
in-app messages are useful for maximizing the content and impact of your user communication. The upper half of a full
in-app message contains an image, and the lower half displays text and up to two click action and analytics-enabled buttons.
This message type extends InAppMessageImmersiveBase
, giving you the option to add custom functionality to your locally generated in-app messages.
HTML
in-app messages are useful for creating fully customized user content. User-defined HTML in-app message content is displayed in a WebView
and may optionally contain other rich content, such as images and fonts, allowing for full control over message appearance and functionality.
These messages instances of InAppMessageHtml
, which implement the IInAppMessage
subclass: IInAppMessageHtml
.
Android in-app messages support a JavaScript brazeBridge
interface to call methods on the Braze Web SDK from within your HTML, see our best practices for more details.
We currently do not support the display of custom HTML in-app messages in an iFrame on the iOS and Android platforms.
You can also define custom in-app message views for your app. For a full walkthrough, see Setting custom factories.
Enabling in-app messages
Step 1: Register BrazeInAppMessageManager
In-app message display is managed by the BrazeInAppMessageManager
class. Every activity in your app must be registered with the BrazeInAppMessageManager
to allow it to add in-app message views to the view hierarchy. There are two ways to accomplish this:
The activity lifecycle callback integration handles in-app message registration automatically; no extra integration is required. This is the recommended method for handling in-app message registration.
If you’re using activity lifecycle callback for automatic registration, do not complete this step.
In your Application.onCreate()
, call ensureSubscribedToInAppMessageEvents()
:
1
BrazeInAppMessageManager.getInstance().ensureSubscribedToInAppMessageEvents(context);
1
BrazeInAppMessageManager.getInstance().ensureSubscribedToInAppMessageEvents(context)
In every activity where in-app messages can be shown, call registerInAppMessageManager()
in that activity’s onResume()
:
1
2
3
4
5
6
7
@Override
public void onResume() {
super.onResume();
// Registers the BrazeInAppMessageManager for the current Activity. This Activity will now listen for
// in-app messages from Braze.
BrazeInAppMessageManager.getInstance().registerInAppMessageManager(activity);
}
1
2
3
4
5
6
public override fun onResume() {
super.onResume()
// Registers the BrazeInAppMessageManager for the current Activity. This Activity will now listen for
// in-app messages from Braze.
BrazeInAppMessageManager.getInstance().registerInAppMessageManager(this)
}
In every activity where registerInAppMessageManager()
was called, call unregisterInAppMessageManager()
in that activity’s onPause()
:
1
2
3
4
5
6
@Override
public void onPause() {
super.onPause();
// Unregisters the BrazeInAppMessageManager for the current Activity.
BrazeInAppMessageManager.getInstance().unregisterInAppMessageManager(activity);
}
1
2
3
4
5
public override fun onPause() {
super.onPause()
// Unregisters the BrazeInAppMessageManager.
BrazeInAppMessageManager.getInstance().unregisterInAppMessageManager(this)
}
Step 2: Update the manager’s blocklist (optional)
In your integration, you may require that certain activities in your app should not show in-app messages. The activity lifecycle callback integration provides an easy way to accomplish this.
The following sample code adds two activities to the in-app message registration blocklist, SplashActivity
and SettingsActivity
:
1
2
3
4
5
6
7
8
9
10
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Set<Class> inAppMessageBlocklist = new HashSet<>();
inAppMessageBlocklist.add(SplashActivity.class);
inAppMessageBlocklist.add(SettingsActivity.class);
registerActivityLifecycleCallbacks(new BrazeActivityLifecycleCallbackListener(inAppMessageBlocklist));
}
}
1
2
3
4
5
6
7
8
9
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val inAppMessageBlocklist = HashSet<Class<*>>()
inAppMessageBlocklist.add(SplashActivity::class.java)
inAppMessageBlocklist.add(SettingsActivity::class.java)
registerActivityLifecycleCallbacks(BrazeActivityLifecycleCallbackListener(inAppMessageBlocklist))
}
}
guide/swift/in_app_messages.md developer_ %}
guide/web/in_app_messages.md developer_ %}
guide/android_ott/in_app_messages.md developer_ %}
guide/cordova/in_app_messages.md developer_ %}
guide/flutter/in_app_messages.md developer_ %}
guide/react_native/in_app_messages.md developer_ %}
guide/roku/in_app_messages.md developer_ %}
guide/tvos/in_app_messages.md developer_ %}
guide/unity/in_app_messages.md developer_ %}
guide/xamarin/in_app_messages.md developer_ %}