{"id":48219,"date":"2025-08-11T17:23:01","date_gmt":"2025-08-11T09:23:01","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=48219"},"modified":"2025-08-11T17:23:01","modified_gmt":"2025-08-11T09:23:01","slug":"%e6%80%8e%e4%b9%88%e6%8a%8a%e4%b8%80%e4%b8%aa%e7%bd%91%e7%ab%99%e5%81%9a%e6%88%90app%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2025\/48219\/","title":{"rendered":"\u600e\u4e48\u628a\u4e00\u4e2a\u7f51\u7ad9\u505a\u6210app\uff1f"},"content":{"rendered":"<p>\u5c06\u7f51\u7ad9\u53d8\u6210\u624b\u673a\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u6280\u80fd\uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5229\u7528\u4f60\u7684\u719f\u7ec3\u6280\u80fd\u5e76\u4f7f\u4f60\u7684\u4ea7\u54c1\u53d8\u5f97\u66f4\u52a0\u53ef\u7528\u6027\u548c\u6613\u7528\u6027\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u624b\u673a\u5e94\u7528\u7a0b\u5e8f\u7684\u539f\u7406\u548c\u6b65\u9aa4\u3002<\/p>\n<p>## \u539f\u7406<\/p>\n<p>\u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f\u975e\u5e38\u5bb9\u6613\u7684\u3002 WebView \u662f\u4e00\u79cd Android \u5e73\u53f0\u63d0\u4f9b\u7684\u57fa\u7840\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u5728\u5e94\u7528\u5185\u90e8\u5d4c\u5165\u7f51\u9875\uff0c\u5c31\u597d\u50cf\u5728\u6d4f\u89c8\u5668\u91cc\u6253\u5f00\u4e00\u6837\u3002\u8fd9\u6837\u505a\u9700\u8981\u4f7f\u7528 JavaScript \u548c HTML \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5bb9\u5668\uff0c\u7528\u4e8e\u5728\u5e94\u7528\u4e2d\u663e\u793a WebView \u548c\u7528\u6237\u754c\u9762\u3002\u8fd9\u4e2a\u5bb9\u5668\u8fde\u63a5\u5230\u4e92\u8054\u7f51\u5e76\u8f7d\u5165\u4f60\u7684\u7f51\u7ad9\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u5e94\u7528\u4e2d\u5229\u7528\u4f60\u7f51\u7ad9\u7684\u5e03\u5c40\u548c\u5176\u4ed6\u7279\u6027\uff0c\u800c\u4e0d\u5fc5\u5728\u5e94\u7528\u4e2d\u91cd\u65b0\u5199\u4ee3\u7801\u3002<\/p>\n<p>## \u6b65\u9aa4<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5f00\u59cb\u5411\u4f60\u5c55\u793a\u628a\u4e00\u4e2a\u7f51\u7ad9\u8f6c\u53d8\u6210\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6b65\u9aa4\u3002<\/p>\n<p>### 1. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Android Studio \u9879\u76ee<\/p>\n<p>\u4ece Android Studio \u7684\u6587\u4ef6\u83dc\u5355\u4e2d\u9009\u62e9 \u201cNew &gt; New Project\u201d \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002<\/p>\n<p>### 2. \u6dfb\u52a0 WebView \u7ec4\u4ef6<\/p>\n<p>\u5728\u9879\u76ee\u7684\u5e03\u5c40\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0 WebView \u7ec4\u4ef6\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6807\u8bb0\u6765\u8f7b\u677e\u5b8c\u6210\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>&#8220;`<\/p>\n<\/p>\n<p>    android:id=&#8221;@+id\/webView&#8221;<\/p>\n<p>    android:layout<a href=\"https:\/\/www.zhidianwl.com\/\">\u7f51\u7ad9\u505aapp<\/a>_width=&#8221;fill_parent&#8221;<\/p>\n<p>    android:layout_height=&#8221;fill_parent&#8221;<\/p>\n<p> \/&gt;<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0c\u8bb0\u5f97\u8ba9 WebView \u8986\u76d6\u6574\u4e2a\u5c4f\u5e55\uff0c\u8fd9\u6837\u4f60\u7684\u5e94\u7528\u5c31\u53ef\u4ee5\u5145\u5206\u5229\u7528\u7528\u6237\u8bbe\u5907\u7684\u7a7a\u95f4\u3002<\/p>\n<p>### 3. \u914d\u7f6e WebView \u8bbe\u7f6e<\/p>\n<p>\u4e3a\u4e86\u4f7f\u4f60\u7684 WebView \u6b63\u786e\u5de5\u4f5c\uff0c\u4f60\u9700\u8981\u4f7f\u7528 JavaScript \u548c WebViewClient \u914d\u7f6e WebView \u8bbe\u7f6e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>webView.getSettings().<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-04\/07\/10\/04386865193.jpg\" \/><\/figure>\n<\/p>\n<p>setJavaScriptEnabled(true);<\/p>\n<p>webView.setWebViewClient(new WebClient());<\/p>\n<p>&#8220;`<\/p>\n<p>### 4. \u7f16\u5199 WebClient \u7c7b<\/p>\n<p>\u4e3a\u4e86\u4f7f\u5e94\u7528\u7a0b\u5e8f\u5728\u6536\u5230\u9519\u8bef\u7f51\u5740\u65f6\u4e0d\u5173\u95ed\uff0c\u4f60\u9700\u8981\u5b9e\u73b0 WebClient \u7c7b\u7684\u4e00\u4e2a\u7248\u672c\u3002WebClient \u7c7b\u9700\u8981\u6269\u5c55 WebViewClient \u7c7b\uff0c\u5b9e\u73b0\u4e00\u4e2a\u540d\u4e3a onReceivedError() \u7684\u65b9\u6cd5\uff0c\u4ee5\u8986\u76d6 WebViewClient \u7c7b\u4e2d\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>public class WebClient extends WebViewClient {<\/p>\n<p>    @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {<\/p>\n<p>        view.loadUrl(&#8220;file:\/\/\/android_asset\/error.html&#8221;);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>### 5.\u52a0\u8f7d\u7f51\u5740<\/p>\n<p>\u5728 onCreate() \u65b9\u6cd5\u4e2d\uff0c\u4e3a WebView \u52a0\u8f7d\u7f51\u5740\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>WebView webView = (WebView) findViewById(R.id.webView);<\/p>\n<p>webView.loadUrl(&#8220;http:\/\/example.com&#8221;);<\/p>\n<p>&#8220;`<\/p>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528 JavaScript\u3001CSS \u548c HTML \u81ea\u5b9a\u4e49 WebView \u7684\u5916\u89c2\u548c\u884c\u4e3a\uff0c\u4f7f\u5b83\u770b\u8d77\u6765\u548c\u611f\u89c9\u50cf\u4e00\u4e2a\u5b8c\u6574\u7684\u5e94\u7528\u7a0b\u5e8f\u800c\u4e0d\u662f\u7f51\u9875\u3002\u56e0\u4e3a WebView \u4f7f\u7528\u539f\u751f Android \u4ee3\u7801\uff0c\u6240\u4ee5\u4f60\u4e5f\u53ef\u4ee5\u8c03\u7528 CameraHelper \u7c7b\u7b49\u5176\u4ed6\u539f\u751f\u529f\u80fd\u3002\u8bf7<a href=\"https:\/\/www.zhidianwl.com\/\">\u667a\u7535\u745e\u521b<\/a>\u786e\u4fdd\u4fdd\u7559\u548c\u6b63\u786e\u5448\u73b0\u5e94\u7528\u7a0b\u5e8f\u7684\u7f29\u7565\u56fe\u3002<\/p>\n<p>### 6. \u6253\u5305\u548c\u53d1\u5e03<\/p>\n<p>\u5728\u4f60\u5b8c\u6210\u6240\u6709\u4fee\u6539\u4e4b\u540e\uff0c\u73b0\u5728\u4f60\u53ef\u4ee5\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u5e76\u53d1\u5e03\u5b83\u4e86\u3002\u8981\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f60\u9700\u8981\u4e3a Android \u548c iPhone \u90fd\u6253\u5305\u3002Android \u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728 Google Play \u5546\u5e97\u4e0a\u53d1\u5e03\uff0c\u800c iPhone \u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728 Apple \u5546\u5e97\u4e0a\u53d1\u5e03\u3002\u4f60\u9700\u8981\u4f7f\u7528\u76f8\u5e94\u7684\u5f00\u53d1\u8005\u5e10\u6237\u6765\u53d1\u5e03\u3002<\/p>\n<p>## \u7ed3\u8bba<\/p>\n<p>\u73b0\u5728\u4f60\u5df2\u7ecf\u77e5\u9053\u5982\u4f55\u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u4f60\u5df2\u7ecf\u719f\u7ec3\u638c\u63e1\u4e86\u5728 Android Studio \u4e2d\u8fdb\u884c\u5f00\u53d1\u7684\u6280\u5de7\u3002\u73b0\u5728\u4f60\u53ef\u4ee5\u4f7f\u7528 WebView \u7ec4\u4ef6\u4f7f\u7528 JavaScript\u3001CSS \u548c HTML \u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u53d1\u5e03\u5230 Google Play \u5546\u5e97\u6216 Apple \u5546\u5e97\u4e2d\uff0c\u5e76\u4e14\u8ba9\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u8bbf\u95ee\u4f60\u7684\u7f51\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u7f51\u7ad9\u53d8\u6210\u624b\u673a\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u6280\u80fd\uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5229\u7528\u4f60\u7684\u719f\u7ec3\u6280\u80fd\u5e76\u4f7f\u4f60\u7684\u4ea7\u54c1\u53d8\u5f97\u66f4\u52a0\u53ef\u7528\u6027\u548c\u6613\u7528\u6027\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u624b\u673a\u5e94\u7528\u7a0b\u5e8f\u7684\u539f\u7406\u548c\u6b65\u9aa4\u3002## \u539f\u7406\u5c06\u7f51\u7ad9\u8f6c\u53d8\u6210\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f\u975e\u5e38<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[65,14,37914,26919,76],"class_list":{"0":"post-48219","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-zuoapp","7":"tag-65","8":"tag-14","9":"tag-app","11":"tag-76"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/48219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=48219"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/48219\/revisions"}],"predecessor-version":[{"id":48289,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/48219\/revisions\/48289"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=48219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=48219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=48219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}