{"id":1285,"date":"2023-03-18T10:12:09","date_gmt":"2023-03-18T02:12:09","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1285"},"modified":"2023-04-29T09:20:36","modified_gmt":"2023-04-29T01:20:36","slug":"jsbridge-add-custom-jump-protocol-for-bridgewebview","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/jsbridge-add-custom-jump-protocol-for-bridgewebview\/","title":{"rendered":"JsBridge\u4e3aBridgeWebView\u6dfb\u52a0\u81ea\u5b9a\u4e49\u8df3\u8f6c\u534f\u8bae"},"content":{"rendered":"<p>JsBridge: <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/lzyzsd\/JsBridge\">https:\/\/github.com\/lzyzsd\/JsBridge<\/a> \u81ea\u5e26\u7684BridgeWebView\u5e76\u672a\u6dfb\u52a0<code>yy:\/\/<\/code>\u4e4b\u5916\u7684\u534f\u8bae\uff0c\u9700\u8981\u81ea\u884c\u5b9e\u73b0\uff0c\u5982\u901a\u7528\u534f\u8bae\u5982\u7535\u8bdd\u3001\u77ed\u4fe1\u3001\u90ae\u4ef6\u4ee5\u53ca\u81ea\u5b9a\u4e49\u534f\u8bae\u5982\u6253\u5f00\u5fae\u4fe1\u7b49\u3002<\/p>\n<pre><code class=\"language-html\">&lt;a href=&quot;tel:10086&quot;&gt;\u7535\u8bdd&lt;\/a&gt;\n&lt;a href=&quot;sms:10086&quot;&gt;\u77ed\u4fe1&lt;\/a&gt;\n&lt;a href=&quot;mailto:yezhou@yezhou.org&quot;&gt;\u90ae\u4ef6&lt;\/a&gt;\n&lt;a href=&quot;weixin:\/\/&quot;&gt;\u6253\u5f00\u5fae\u4fe1&lt;\/a&gt;<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">private WebViewClient getWebViewClient() {\n    return new WebViewClient() {\n        BridgeWebViewClient mBridgeWebViewClient = new BridgeWebViewClient(mBridgeWebView);\n\n        @RequiresApi(api = Build.VERSION_CODES.N)\n        @Override\n        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {\n            NLog.i(Constants.TAG, &quot;url: &quot; + request.getUrl().toString());\n            String url = request.getUrl().toString();\n            if (shouldOverrideUrlLoading(url)) {\n                return true;\n            } else {\n                return mBridgeWebViewClient.shouldOverrideUrlLoading(view, request);\n            }\n        }\n\n        @Override\n        public boolean shouldOverrideUrlLoading(WebView view, String url) {\n            NLog.i(Constants.TAG, &quot;url: &quot; + url);\n            if (shouldOverrideUrlLoading(url)) {\n                return true;\n            } else {\n                return mBridgeWebViewClient.shouldOverrideUrlLoading(view, url);\n            }\n        }\n\n        @Override\n        public void onPageStarted(WebView view, String url, Bitmap favicon) {\n            mBridgeWebViewClient.onPageStarted(view, url, favicon);\n        }\n\n        @Override\n        public void onPageFinished(WebView view, String url) {\n            \/\/super.onPageFinished(view, url);\n            mBridgeWebViewClient.onPageFinished(view, url);\n        }\n\n        @TargetApi(Build.VERSION_CODES.M)\n        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)\n        @Override\n        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {\n            super.onReceivedError(view, request, error);\n            \/\/yy:\/\/__QUEUE_MESSAGE__\/\n            LogUtils.i(TAG, &quot;onReceivedError:&quot; + error.getDescription() + &quot; code:&quot; + error.getErrorCode() + &quot;, url: &quot; + request.getUrl().toString());\n        }\n\n        private boolean shouldOverrideUrlLoading(String url) {\n            if (url.startsWith(WebView.SCHEME_TEL) || url.startsWith(SCHEME_SMS) || url.startsWith(WebView.SCHEME_MAILTO)) {\n                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));\n                LianLianServiceActivity.this.startActivity(intent);\n                return true;\n            } else if (url.startsWith(&quot;weixin:&quot;)) {\n                \/\/\u8df3\u8f6c\u5fae\u4fe1\n                Intent launch = getPackageManager().getLaunchIntentForPackage(&quot;com.tencent.mm&quot;);\n                if (launch == null) {\n                    Toast.makeText(LianLianServiceActivity.this, &quot;Wechat not installed&quot;, Toast.LENGTH_SHORT).show();\n                    return true;\n                }\n                Intent intent = new Intent(Intent.ACTION_MAIN);\n                intent.addCategory(Intent.CATEGORY_LAUNCHER);\n                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n                intent.setComponent(launch.getComponent());\n                startActivity(intent);\n                return true;\n            }\n            return false;\n        }\n    };\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JsBridge: https:\/\/github.com\/lzyzsd\/JsBridge \u81ea\u5e26\u7684BridgeW [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[320],"class_list":["post-1285","post","type-post","status-publish","format-standard","hentry","category-android-advance","tag-jsbridge"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1285"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1285\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}