{"id":17665,"date":"2024-03-06T13:34:47","date_gmt":"2024-03-06T05:34:47","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=17665"},"modified":"2024-03-06T13:34:47","modified_gmt":"2024-03-06T05:34:47","slug":"app%e5%8f%af%e4%bb%a5%e5%81%9a%e7%bd%91%e9%a1%b5%e7%89%88%e5%90%97","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/17665\/","title":{"rendered":"app\u53ef\u4ee5\u505a\u7f51\u9875\u7248\u5417?"},"content":{"rendered":"
(function () {
\n const hs = [“yimenapp.com”, “yimenapp.net”, “yimenapp.cn”];
\n for (var i = 0, len = hs.length; i < len; i++) {
\n if (location.host.endsWith(hs[i])) {
\n document.write('’);
\n break;
\n }
\n }
\n})();<\/p>\n
\u53ef\u4ee5\uff0c\u73b0\u5728\u5f88\u591aAPP\u90fd\u63d0\u4f9b\u4e86\u7f51\u9875\u7248\uff0c\u6bd4\u5982\u5fae\u4fe1\u3001\u652f\u4ed8\u5b9d\u3001\u6dd8\u5b9d\u7b49\u7b49\u3002\u90a3\u4e48\uff0cAPP\u5982\u4f55\u5b9e\u73b0\u7f51\u9875\u7248\u5462\uff1f\u672c\u6587\u5c06\u4ece\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u4e24\u65b9\u9762\u6765\u8bb2\u89e3\u3002<\/p>\n
\u4e00\u3001\u539f\u7406<\/p>\n
APP\u53ef\u4ee5\u5b9e\u73b0\u7f51\u9875\u7248\u7684\u539f\u7406\u4e3b\u8981\u662f\u901a\u8fc7WebView\u63a7\u4ef6\u5b9e\u73b0\u7684\u3002WebView\u662fAndroid\u7cfb\u7edf\u63d0\u4f9b\u7684\u4e00\u4e2a\u53ef\u4ee5\u5728\u5e94\u7528\u4e2d\u5c55\u793a\u7f51\u9875\u7684\u63a7\u4ef6\uff0c\u5b83\u53ef\u4ee5\u52a0\u8f7d\u7f51\u9875\u5e76\u663e\u793a\u5728\u5e94\u7528\u4e2d\uff0c\u540c\u65f6\u4e5f\u652f\u6301JavaScript\u811a\u672c\u7684\u6267\u884c\u3002<\/p>\n
\u5f53\u7528\u6237\u5728APP\u4e2d\u70b9\u51fb\u8fdb\u5165\u7f51\u9875\u65f6\uff0cAPP\u4f1a\u521b\u5efa\u4e00\u4e2aWebView\u63a7\u4ef6\uff0c\u7136\u540e\u5c06\u7f51\u9875\u7684URL\u4f20\u9012\u7ed9WebView\u63a7\u4ef6\u8fdb\u884c\u52a0\u8f7d\uff0c\u6700\u7ec8\u5c06\u7f51\u9875\u5c55\u793a\u5728\u5e94\u7528\u4e2d\u3002\u6b64\u65f6\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5e94\u7528\u4e2d\u8fdb\u884c\u7f51\u9875\u7684\u6d4f\u89c8\u548c\u64cd\u4f5c\uff0c\u5c31\u50cf\u5728\u666e\u901a\u6d4f\u89c8\u5668\u4e2d\u4e00\u6837\u3002<\/p>\n
\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n
1. \u521b\u5efaWebView\u63a7\u4ef6<\/p>\n
\u5728APP\u4e2d\u521b\u5efaWebView\u63a7\u4ef6\u9700\u8981\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\u6dfb\u52a0WebView\u63a7\u4ef6\uff0c\u5e76\u5728Java\u4ee3\u7801\u4e2d\u83b7\u53d6WebView\u63a7\u4ef6\u7684\u5b9e\u4f8b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n
“`<\/p>\n<\/p>\n
android:id=”@+id\/webview”<\/p>\n
android:layout_width=”match_parent”<\/p>\n
android:layout_height=”match_parent” \/><\/p>\n
“`<\/p>\n
Java\u4ee3\u7801\uff1a<\/p>\n
“`<\/p>\n
WebView webView = findViewById(R.id.webview);<\/p>\n
“`<\/p>\n
2. \u52a0\u8f7d\u7f51\u9875<\/p>\n
\u5728\u83b7\u53d6\u5230WebView\u63a7\u4ef6\u7684\u5b9e\u4f8b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528WebView\u63a7\u4ef6\u7684loadUrl()\u65b9\u6cd5\u6765\u52a0\u8f7d\u7f51\u9875\u4e86\u3002\u8be5\u65b9\u6cd5\u63a5\u6536\u4e00\u4e2a\u7f51\u9875\u7684URL\u4f5c\u4e3a\u53c2\u6570\uff0c\u7136\u540e\u4f1a\u5c06\u8be5URL\u5bf9\u5e94\u7684\u7f51\u9875\u52a0\u8f7d\u5230WebView\u63a7\u4ef6\u4e2d\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
“`<\/p>\n
webView.loadUrl(“http:\/\/www.example.com”);<\/p>\n
“`<\/p>\n
3. \u652f\u6301JavaScript<\/p>\n