Adding The Braze JavaScript Interface to Webviews

Using Braze functionality from a WebView in your app can be done by adding the Braze JavaScript interface to your WebView as shown below. Once 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 = AppboyFileUtils.getAssetFileStringContents(context.getAssets(), "appboy-html-in-app-message-javascript-component.js");
myWebView.loadUrl("javascript:" + javascriptString);

final AppboyInAppMessageHtmlJavascriptInterface javascriptInterface = new AppboyInAppMessageHtmlJavascriptInterface(context, inAppMessage);
myWebView.addJavascriptInterface(javascriptInterface, "appboyInternalBridge");
1
2
3
4
5
val javascriptString = AppboyFileUtils.getAssetFileStringContents(context.getAssets(), "appboy-html-in-app-message-javascript-component.js")
myWebView.loadUrl("javascript:" + javascriptString!!)

val javascriptInterface = AppboyInAppMessageHtmlJavascriptInterface(context, inAppMessage)
myWebView.addJavascriptInterface(javascriptInterface, "appboyInternalBridge")
WAS THIS PAGE HELPFUL?
New Stuff!