diff --git a/library/src/main/java/com/github/lzyzsd/jsbridge/BridgeWebView.java b/library/src/main/java/com/github/lzyzsd/jsbridge/BridgeWebView.java index 37f69a1..a72157a 100644 --- a/library/src/main/java/com/github/lzyzsd/jsbridge/BridgeWebView.java +++ b/library/src/main/java/com/github/lzyzsd/jsbridge/BridgeWebView.java @@ -8,6 +8,7 @@ import androidx.collection.ArrayMap; import android.text.TextUtils; import android.util.AttributeSet; +import android.webkit.WebView; import android.util.Log; import android.webkit.JavascriptInterface; import android.webkit.WebSettings; @@ -25,6 +26,11 @@ @SuppressLint("SetJavaScriptEnabled") public class BridgeWebView extends WebView implements WebViewJavascriptBridge, BridgeWebViewClient.OnLoadJSListener { + private final int URL_MAX_CHARACTER_NUM=2097152; + public static final String toLoadJs = "WebViewJavascriptBridge.js"; + Map responseCallbacks = new HashMap(); + Map messageHandlers = new HashMap(); + BridgeHandler defaultHandler = new DefaultHandler(); private Map mCallbacks = new ArrayMap<>(); private List mMessages = new ArrayList<>(); @@ -192,7 +198,11 @@ private void dispatchMessage(Object message) { String javascriptCommand = String.format(BridgeUtil.JS_HANDLE_MESSAGE_FROM_JAVA, messageJson); // 必须要找主线程才会将数据传递出去 --- 划重点 if (Thread.currentThread() == Looper.getMainLooper().getThread()) { - this.loadUrl(javascriptCommand); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT&&javascriptCommand.length()>=URL_MAX_CHARACTER_NUM) { + this.evaluateJavascript(javascriptCommand,null); + }else { + this.loadUrl(javascriptCommand); + } } }