I am loading the content of a local html file into a WebView:
context?.assets?.open("SeatingPlan.html")?.bufferedReader().use {
val some = it?.readText()
some.let {
val finalHTML = some!!.replace("{PERFORMANCE-ID}", occurrence.id.toString())
binding.webView.addJavascriptInterface(SeatingPlanWebAppInterface { ticketData: String ->
handleTicketSelection(ticketData)
}, "Android")
binding.webView.loadData(finalHTML, "text/html; charset=utf-8", "UTF-8")
}
}
Then, I have a listener so as I will trigger some javascript functions once the loading is finished as follows:
binding.webView.settings.javaScriptEnabled = true
binding.webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
binding.webView.loadUrl("javascript:(function() {" + "document.addEventListener('LTD.SeatPlan.OnSeatSelected', e => {Android.seatSelected(JSON.stringify(e.detail))});" + "document.addEventListener('LTD.SeatPlan.OnSeatUnselected', e => {Android.seatUnSelected(JSON.stringify(e.detail))});" + "})();")
}
}
The same code has been working well for all supported android versions of my app (5.0+), while now, after updating to target sdk 29 it gets stuck in loading the html and instead it shows a blank white screen.
I am thinking that the issue may be related to the changes made for SDK
29 , but don't know where else to look for a solution. The reason I am thinking it may be the target SDK
29 the issue is because of the latest changes relating to the WebView
that were made: https://developer.android.com/about/versions/pie/android-9.0-migration. Is there a workaround?