agentWeb.getJsInterfaceHolder().addJavaObject("testApp", AndroidInterface())
inner class AndroidInterface {
@JavascriptInterface
fun showAppMessage(s: String) {
Toaster.show("安卓JS点击了" + s)
Handler().postDelayed({
agentWeb.getJsAccessEntrace().quickCallJs("androidShowMessage", "55555555555")
}, 3000)
}
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试交互</title>
</head>
<body>
<button onclick="testShow()">点击调用</button>
<script>
function testShow() {
alert('点击了')
testApp.showAppMessage('66666666666')
}
function androidShowMessage(data) {
alert(data)
}
</script>
</body>
</html>
网友评论