代码拉取完成,页面将自动刷新
同步操作将从 hcanyz/ZJsBridge 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
参考微信jsBridge的一套完整的native-bridge-web协议与实现,清晰规范的开发Hybrid App
Support API v19+
Support androidx
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.hcanyz:ZJsBridge:$version'
}
class WebView : WebView, IZWebView {
private val zWebHelper: ZWebHelper by lazy { ZWebHelper(this) }
override fun getCurUrl(): String {
return url
}
override fun getCurContext(): Context {
return context
}
override fun getCurZWebHelper(): ZWebHelper {
return zWebHelper
}
override fun execJs(methodName: String, params: String?, valueCallback: ValueCallback<String>?) {
val js: String = if (params.isNullOrBlank()) {
String.format("%s()", methodName)
} else {
String.format("%s('%s')", methodName, params)
}
execJs(js, valueCallback)
}
override fun execJs(sourceJs: String, valueCallback: ValueCallback<String>?) {
if (ZJsBridge.ZJS_DEBUG) ZJsBridge.log("evaluateJavascript:javascript:$sourceJs")
runOnMainThread(Runnable {
evaluateJavascript("javascript:$sourceJs") { valueCallback?.onReceiveValue(it) }
})
}
override fun runOnMainThread(runnable: Runnable) {
if (Looper.getMainLooper() == Looper.myLooper()) {
runnable.run()
return
}
post(runnable)
}
}
addJavascriptInterface(ZJavascriptInterface(this), "__zf")
private inner class InnerCustomWebViewClient : WebViewClient() {
override fun onPageFinished(webView: WebView?, s: String?) {
super.onPageFinished(webView, s)
zWebHelper.injectCoreJs()
}
override fun doUpdateVisitedHistory(p0: WebView?, p1: String?, p2: Boolean) {
super.doUpdateVisitedHistory(p0, p1, p2)
zWebHelper.injectCoreJs()
}
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
val zWebResourceResponse = zWebHelper.hookNativeResourceWithWebViewRequest(request.url)
if (zWebResourceResponse != null) {
return WebResourceResponse(zWebResourceResponse.mimeType, "", zWebResourceResponse.data)
}
return super.shouldInterceptRequest(view, request)
}
}
web_test.getCurZWebHelper().registeredJsApiHandler(this, ZCommonJsHandler::class.java)
web_test.getCurZWebHelper().registeredJsApiHandler(this, ImageJsHandler::class.java)
override fun closeWindow() {
finish()
}
override fun updateTitle(title: String) {
tv_test_tile.text = title
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
web_test.getCurZWebHelper().dispatchContainerResult(requestCode, resultCode, data)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
web_test.getCurZWebHelper().dispatchContainerDestroy()
}
override fun onBackPressed() {
if (web_test.canGoBack()) {
web_test.goBack()
} else {
super.onBackPressed()
}
}
这个库提供了一个h5的api测试页面
本项目中已集成一个打包后的产物,可以自行编译替换(ZJsBridge\app\src\main\assets)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。