HTML in-app messages
Learn how to add the Braze JavaScript interface to your Android and FireOS apps, so you can use the Braze API to create HTML in-app messages in your custom WebViews.
How it works
With the Braze JavaScript interface, you can leverage Braze inside the custom WebViews within your app. The interface’s ScriptMessageHandler
is responsible for:
- Injecting the Braze Javascript bridge into your WebView, as outlined in HTML in-app messages.
- Passing the bridge methods received from your WebView to the Braze Android SDK.
Adding the interface to a WebView
Using Braze functionality from a WebView in your app can be done by adding the Braze JavaScript interface to your WebView. After the interface has been added, the same API available for HTML in-app messages will be available within your custom WebView.
1
2
3
4
5
String javascriptString = BrazeFileUtils.getAssetFileStringContents(context.getAssets(), "braze-html-bridge.js");
myWebView.loadUrl("javascript:" + javascriptString);
final InAppMessageJavascriptInterface javascriptInterface = new InAppMessageJavascriptInterface(context, inAppMessage);
myWebView.addJavascriptInterface(javascriptInterface, "brazeInternalBridge");
1
2
3
4
5
val javascriptString = context.assets.getAssetFileStringContents("braze-html-bridge.js")
myWebView.loadUrl("javascript:" + javascriptString!!)
val javascriptInterface = InAppMessageJavascriptInterface(context, inAppMessage)
myWebView.addJavascriptInterface(javascriptInterface, "brazeInternalBridge")
New Stuff!