I'm using kotlin to develop the native application which have a webview and some functions for the webview javascript.
User can click the button on the page then call the native toast or alert dialog
I finished the functions and it work perfectly, now I want to add the callback function
into the dialog, when user click OK button (positive button), it will run the javascript on the webpage,
Javascript on webpage
Android.showAlert("Title","Message",function(){alert(123)});
JavascriptInterface
@JavascriptInterface
fun showAlert(title:String,msg: String, callBack: Any?) {
val alertDialog = AlertDialog.Builder(mContext)
alertDialog.setTitle(title).setMessage(msg)
alertDialog.setPositiveButton("OK") { _, _->callBack())}
alertDialog.show()
Log.d('check',callBack) // Logged callback is null
}
The code seems cannot receive the callback function, how can I solve it and run the callback?
Thanks