Mobile Popup Android
Configuration
Name | Detail | Example |
---|---|---|
titleText | Title | Recommend Campaign |
subtitleText | Subtitle | See Details with the button below |
titleColor | Title Color | #333333 (HEX, RGBA ,etc) |
titleFontSize | Title Font Size | 30px |
bannerUrl | Image Path | https://****.jpg |
closeButtonText | Close Button Text | Close |
linkButtonText | Link Button Text | See Details |
linkButtonUrl | Link Button URL | https:// or app:// |
※ Set these properties of Mobile Data Campaign
Installation Step
- Set Mobile Data Campaign with the documentation
- Open the file downloaded on the top page
- Place
popup.html
frommobile
>popup
>android
to the local directory - Add the code below inside onStart method of Activity Class
@Override
handlerPopup = CampaignHandler { campaign ->
if (!campaign.isControlGroup) {
// webview setting
val builder = AlertDialog.Builder(this);
val popupWebView = WebView(this)
builder.setView(popupWebView);
val alertDialog = builder.create();
popupWebView.loadUrl("file:///android_asset/popup.html")
popupWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
// Handle URL clicked inside the webview
Log.d("CLICK", request.url.toString())
return true
}
override fun onPageFinished(view: WebView, urlString: String) {
// Pass the data of Mobile Data Campaign to webview
popupWebView.loadUrl(
"javascript:loadVariables(${campaign.data})"
)
}
}
popupWebView.settings.domStorageEnabled = true
popupWebView.settings.javaScriptEnabled = true
popupWebView.addJavascriptInterface(WebAppInterface(this, alertDialog), "Android")
alertDialog.show()
}
}
// Here it sets "App Foreground" to trigger Mobile Data Campaign
screen.trackAction("App Foreground")
screen.setCampaignHandler(this.handlerPopup, "the value you set as Target")
- Add the code below in the same file of "4". You can set it in a different file.
class WebAppInterface(private val mContext: MainActivity, private val alertDialog: AlertDialog) {
@JavascriptInterface
fun closeDialog(toast: String) {
alertDialog.dismiss()
}
}