{"id":5434,"date":"2021-11-04T15:39:12","date_gmt":"2021-11-04T07:39:12","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress\/?p=5434"},"modified":"2025-07-07T10:58:30","modified_gmt":"2025-07-07T02:58:30","slug":"webview","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434","title":{"rendered":"WebView"},"content":{"rendered":"<p><a href=\"https:\/\/www.jianshu.com\/p\/d2f5ae6b4927\">https:\/\/www.jianshu.com\/p\/d2f5ae6b4927<\/a><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E5%9B%9E%E9%80%80%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC\" title=\"\u56de\u9000\u4e8b\u4ef6\u76d1\u542c\">\u56de\u9000\u4e8b\u4ef6\u76d1\u542c<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#Android_%E4%B8%ADwebview%E8%BD%BD%E5%85%A5%E7%BD%91%E9%A1%B5%E6%80%BB%E6%98%AF%E8%B7%B3%E5%88%B0%E6%B5%8F%E8%A7%88%E5%99%A8\" title=\"Android \u4e2dwebview\u8f7d\u5165\u7f51\u9875\u603b\u662f\u8df3\u5230\u6d4f\u89c8\u5668\">Android \u4e2dwebview\u8f7d\u5165\u7f51\u9875\u603b\u662f\u8df3\u5230\u6d4f\u89c8\u5668<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E5%8A%A0%E8%BD%BD%E4%B8%8D%E5%87%BA%E7%BD%91%E9%A1%B5%E5%86%85%E5%AE%B9This_request_has_been_blocked_the_content_must_be_served_over_HTTPS\" title=\"\u52a0\u8f7d\u4e0d\u51fa\u7f51\u9875\u5185\u5bb9This request has been blocked; the content must be served over HTTPS.\">\u52a0\u8f7d\u4e0d\u51fa\u7f51\u9875\u5185\u5bb9This request has been blocked; the content must be served over HTTPS.<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#WebView%E6%8B%A6%E6%88%AA%E5%8C%85%E6%8B%ACH5%E5%86%85%E9%83%A8%E6%89%80%E6%9C%89%E7%9A%84url\" title=\"WebView\u62e6\u622a\u5305\u62ecH5\u5185\u90e8\u6240\u6709\u7684url\">WebView\u62e6\u622a\u5305\u62ecH5\u5185\u90e8\u6240\u6709\u7684url<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E5%8A%A0%E8%BD%BD%E6%9C%AC%E5%9C%B0html\" title=\"\u52a0\u8f7d\u672c\u5730html\">\u52a0\u8f7d\u672c\u5730html<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#WebView%E5%8A%A0%E8%BD%BDhtml%E7%89%87%E6%AE%B5\" title=\"WebView\u52a0\u8f7dhtml\u7247\u6bb5\">WebView\u52a0\u8f7dhtml\u7247\u6bb5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E5%BC%80%E5%90%AFjs%E8%B0%83%E8%AF%95\" title=\"\u5f00\u542fjs\u8c03\u8bd5\">\u5f00\u542fjs\u8c03\u8bd5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E7%9B%91%E5%90%AC%E7%BD%91%E9%A1%B5%E5%8A%A0%E8%BD%BD%E5%AE%8C%E6%AF%95\" title=\"\u76d1\u542c\u7f51\u9875\u52a0\u8f7d\u5b8c\u6bd5\">\u76d1\u542c\u7f51\u9875\u52a0\u8f7d\u5b8c\u6bd5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E6%B8%85%E7%90%86%E7%BC%93%E5%AD%98\" title=\"\u6e05\u7406\u7f13\u5b58\">\u6e05\u7406\u7f13\u5b58<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=5434\/#%E6%97%A0%E6%B3%95%E5%BC%B9%E5%87%BA%E8%BD%AF%E9%94%AE%E7%9B%98%E7%9A%84%E5%8E%9F%E5%9B%A0%E5%8F%8A%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95\" title=\"\u65e0\u6cd5\u5f39\u51fa\u8f6f\u952e\u76d8\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u529e\u6cd5\">\u65e0\u6cd5\u5f39\u51fa\u8f6f\u952e\u76d8\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u529e\u6cd5<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"%E5%9B%9E%E9%80%80%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC\"><\/span>\u56de\u9000\u4e8b\u4ef6\u76d1\u542c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-java\">  if(webView.canGoBack()){\n   webView.goBack(); \/\/ goBack()\u8868\u793a\u8fd4\u56deWebView\n  }else {\n   finish();\n  }<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Android_%E4%B8%ADwebview%E8%BD%BD%E5%85%A5%E7%BD%91%E9%A1%B5%E6%80%BB%E6%98%AF%E8%B7%B3%E5%88%B0%E6%B5%8F%E8%A7%88%E5%99%A8\"><\/span>Android \u4e2dwebview\u8f7d\u5165\u7f51\u9875\u603b\u662f\u8df3\u5230\u6d4f\u89c8\u5668<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u590d\u5199shouldOverrideUrlLoading\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">  wvIndexWeb.setWebViewClient(new WebViewClient(){\n        @Override\n        public boolean shouldOverrideUrlLoading(WebView view, String url) {\n            view.loadUrl(url);\n            return true;\n        }\n    });<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E8%BD%BD%E4%B8%8D%E5%87%BA%E7%BD%91%E9%A1%B5%E5%86%85%E5%AE%B9This_request_has_been_blocked_the_content_must_be_served_over_HTTPS\"><\/span>\u52a0\u8f7d\u4e0d\u51fa\u7f51\u9875\u5185\u5bb9This request has been blocked; the content must be served over HTTPS.<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><a href=\"https:\/\/blog.csdn.net\/jia635\/article\/details\/70257212\">https:\/\/blog.csdn.net\/jia635\/article\/details\/70257212<\/a><\/p>\n<p>\u6dfb\u52a0\u8bbe\u7f6e\uff1a<\/p>\n<pre><code class=\"language-java\">  WebSettings settings = webView.getSettings();\n                            settings.setJavaScriptEnabled(true);\n                            settings.setDomStorageEnabled(true);\n                            settings.setAllowFileAccess(true);\n                            settings.setAppCacheEnabled(true);\n\n                            if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {\n                                webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);\n                            }<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"WebView%E6%8B%A6%E6%88%AA%E5%8C%85%E6%8B%ACH5%E5%86%85%E9%83%A8%E6%89%80%E6%9C%89%E7%9A%84url\"><\/span>WebView\u62e6\u622a\u5305\u62ecH5\u5185\u90e8\u6240\u6709\u7684url<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><a href=\"http:\/\/www.deiniu.com\/article\/191250.htm\">http:\/\/www.deiniu.com\/article\/191250.htm<\/a><\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E8%BD%BD%E6%9C%AC%E5%9C%B0html\"><\/span>\u52a0\u8f7d\u672c\u5730html<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><a href=\"https:\/\/www.jianshu.com\/p\/6c796944a19f\">https:\/\/www.jianshu.com\/p\/6c796944a19f<\/a><br \/>\n<img src=\"http:\/\/xinyiworld.top\/wordpress\/wp-content\/uploads\/2021\/11\/6424104-b401fddc6435ce37.png\" alt=\"\" \/><\/p>\n<p><code>webView.loadUrl(&quot;file:\/\/\/android_asset\/web\/index.html&quot;);<\/code><\/p>\n<h4><span class=\"ez-toc-section\" id=\"WebView%E5%8A%A0%E8%BD%BDhtml%E7%89%87%E6%AE%B5\"><\/span>WebView\u52a0\u8f7dhtml\u7247\u6bb5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><code>loadDataWithBaseURL(null, htmlContent, &quot;text\/html&quot;, &quot;utf-8&quot;, null);<\/code><\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E5%BC%80%E5%90%AFjs%E8%B0%83%E8%AF%95\"><\/span>\u5f00\u542fjs\u8c03\u8bd5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-java\">\/\/\u662f\u5426\u5141\u8bb8web\u6d4f\u89c8\u5668\u8c03\u8bd5\nif (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {\nWebView.setWebContentsDebuggingEnabled(isDebug());\n}\n\nsetWebChromeClient(new WebChromeClient() {\n            \/\/return true\u8868\u793a\u5141\u8bb8\u5f00\u542fjs\u8c03\u8bd5\u5de5\u5177\uff0c\u6709\u7684\u624b\u673a\u9700\u8981\u590d\u5199\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u6709\u7684\u4e0d\u9700\u8981\u3002\n            @Override\n            public boolean onConsoleMessage(ConsoleMessage consoleMessage) {\n                return isDebug();\n            }\n        });<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E7%9B%91%E5%90%AC%E7%BD%91%E9%A1%B5%E5%8A%A0%E8%BD%BD%E5%AE%8C%E6%AF%95\"><\/span>\u76d1\u542c\u7f51\u9875\u52a0\u8f7d\u5b8c\u6bd5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-java\">\/\/\u9632\u6b62\u81ea\u52a8\u6253\u5f00\u7cfb\u7edf\u6d4f\u89c8\u5668\u52a0\u8f7d\nsetWebViewClient(new WebViewClient() {\n   @Override\n   public void onPageStarted(WebView view, String url, Bitmap favicon) {\n      if (onPageLoadListener != null) {\nonPageLoadListener.onPageStarted(view, url, favicon);\n      }\n   }\n\n   @Override\n   public void onPageFinished(WebView view, String url) {\n     if (onPageLoadListener != null) {\nonPageLoadListener.onPageFinished(view,url);\n     }\n   }\n});<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E6%B8%85%E7%90%86%E7%BC%93%E5%AD%98\"><\/span>\u6e05\u7406\u7f13\u5b58<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u6709\u65f6\u5019js\u660e\u660e\u4fee\u6539\u4e86\uff0c\u4f46\u662fjs\u7684\u95ee\u9898\u4f9d\u7136\u5b58\u5728\uff0c\u9700\u8981\u6e05\u7406\u4e00\u4e0bWebView\u7684\u7f13\u5b58\u3002<\/p>\n<pre><code class=\"language-java\">mCurrentWebView.clearCache(true);\n\nmCurrentWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E6%97%A0%E6%B3%95%E5%BC%B9%E5%87%BA%E8%BD%AF%E9%94%AE%E7%9B%98%E7%9A%84%E5%8E%9F%E5%9B%A0%E5%8F%8A%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95\"><\/span>\u65e0\u6cd5\u5f39\u51fa\u8f6f\u952e\u76d8\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u529e\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u4e0b\u9762\u7684\u5730\u65b9\u4e0d\u53ef\u4f200<br \/>\n<img src=\"http:\/\/xinyiworld.top\/wordpress_it\/wp-content\/uploads\/2021\/11\/bmltYV8yMTU4MjI4MjgzNV8xNjUyMjUxNTE5MjU2XzE3YzI2YWQxLTNhN2YtNDhlYi1iOGE1LTk5ODQzNjI1NzIyOQ.png\" alt=\"\" \/><\/p>\n<button class=\"simplefavorite-button\" data-postid=\"5434\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.jianshu.com\/p\/d2f5ae6b4927 \u76ee\u5f55 \u56de\u9000\u4e8b\u4ef6\u76d1\u542cAn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[334],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/5434"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5434"}],"version-history":[{"count":13,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/5434\/revisions"}],"predecessor-version":[{"id":15746,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/5434\/revisions\/15746"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5434"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}