Skip to main content

Mobile Popup Android

Configuration

NameDetailExample
titleTextTitleRecommend Campaign
subtitleTextSubtitleSee Details with the button below
titleColorTitle Color#333333 (HEX, RGBA ,etc)
titleFontSizeTitle Font Size30px
bannerUrlImage Pathhttps://****.jpg
closeButtonTextClose Button TextClose
linkButtonTextLink Button TextSee Details
linkButtonUrlLink Button URLhttps:// or app://

※ Set these properties of Mobile Data Campaign

Installation Step

  1. Set Mobile Data Campaign with the documentation
  2. Open the file downloaded on the top page
  3. Place popup.html from mobile > popup > android to the local directory
  4. 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")
  1. 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()
}
}