WebView Implementation
Android SDK
Adding Primis Player to a WebView presenting HTML content
- Adding an Html Div element to the web page
PrimisPlayer is overlaid on top of the web content in this type of integration. The Html page has to contain a div element that will mark the player's position and width. Its height will be updated later by PrimisPlayer.
Add an Html div element to your web page with id=”primisPlayerSdkPlaceholder”
<div id="primisPlayerSdkPlaceholder"></div>
You may wish to include style attributes to control position and width.
for example:
<div id="primisPlayerSdkPlaceholder", style="width: 90%; margin:auto;">It is required that the div element will have opening and closing tags.
Do not do:
<div id="primisPlayerSdkPlaceholder”/>
- Initializing and configuring the player
Add an instance variable for the Primis player:
var primisPlayer: PrimisPlayer? = null
- Adding an interface to allow PrimisPlayer to identify changes in the web page content height
private lateinit var primisJSInterface: PrimisScrollJSInterface
...
primisJSInterface = PrimisScrollJSInterface()
webView.addJavascriptInterface(
primisJSInterface, PrimisScrollJSInterface.Companion.PRIMIS_SCROLL_JS_INTERFACE_OBJ
)
- Initializing the player
Implement the WebViewClient interface method onPageFinished and Initialize the player inside it. The player will require a placementId string and your WebView.
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished( view: WebView, url: String) {
super.onPageFinished(view, url)
// Initialize the PrimisPlayer here
primisPlayer = PrimisConfiguration.Builder()
.placement("123456")// The placement ID
.hostAppWebView(webView) // The WebView
.hostAppWebViewJSInterface(primisJSInterface) // The WebView interface
.createPlayer(applicationContext)
primisPlayer.add()
}
}
webView.loadUrl(url)
In case of using WEB GDPR Consent you need to set the host application Consent Type as Consent.Type.WEB_CONSENT. For more information on how to set it please refer to the “Consent” section under “Advanced features”.
- Removing Primis Player
Call PrimisPlayer.remove when the view is about to be destroyed (e.g. onDestroy(), onDestroyView())
primisPlayer?.let {
it.remove()
primisPlayer = null
}
Updated 12 months ago