{"id":14204,"date":"2024-01-02T18:32:37","date_gmt":"2024-01-02T10:32:37","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=14204"},"modified":"2024-01-02T18:32:37","modified_gmt":"2024-01-02T10:32:37","slug":"%e6%8a%8a%e7%bd%91%e9%a1%b5%e7%94%9f%e6%88%90app%e6%93%8d%e4%bd%9c%e6%ad%a5%e9%aa%a4%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/14204\/","title":{"rendered":"\u628a\u7f51\u9875\u751f\u6210app\u64cd\u4f5c\u6b65\u9aa4\u4ecb\u7ecd"},"content":{"rendered":"

\u5c06\u7f51\u9875\u751f\u6210APP\uff0c\u5373\u5c06\u7f51\u9875\u5e94\u7528\uff08Web App\uff09\u8f6c\u6362\u4e3a\u539f\u751f\u5e94\u7528\uff08Native App\uff09\u7684\u8fc7\u7a0b\u3002\u539f\u751f\u5e94\u7528\u6307\u7684\u662f\u4e13\u95e8\u4e3a\u67d0\u4e2a\u64cd\u4f5c\u7cfb\u7edf\uff08\u5982Android\u6216iOS\uff09\u8bbe\u8ba1\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u79cd\u8f6c\u6362\u53ef\u4ee5\u8ba9\u7528\u6237\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u66f4\u65b9\u4fbf\u5730\u8bbf\u95ee\u7f51\u7ad9\uff0c\u5e76\u83b7\u5f97\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n

\u4e00\u3001\u539f\u7406\u7b80\u8ff0<\/p>\n

\u5c06\u7f51\u9875\u751f\u6210APP\u7684\u6838\u5fc3\u662fWebView\u3002WebView\u662f\u4e00\u79cd\u5728\u539f\u751f\u5e94\u7528\u5185\u90e8\u5d4c\u5165\u7f51\u9875\u7684\u63a7\u4ef6\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u52a0\u8f7d\u548c\u663e\u793aWeb\u5185\u5bb9\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u5305\u542bWebView\u7684\u539f\u751f\u5e94\u7528\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06Web\u5e94\u7528\u201c\u5305\u88c5\u201d\u8d77\u6765\uff0c\u4f7f\u5176\u770b\u4e0a\u53bb\u4e0e\u539f\u751f\u5e94\u7528\u65e0\u5f02\u3002<\/p>\n

\u4e8c\u3001\u8be6\u7ec6\u6b65\u9aa4<\/p>\n

\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u7f51\u9875\u8f6c\u5316\u4e3aAndroid APP\u4e3a\u4f8b\u7684\u8fc7\u7a0b\uff1a<\/p>\n

1. \u51c6\u5907<\/p>\n

<\/figure>\n<\/p>\n

\u5de5\u5177\uff1a\u4e3a\u4e86\u5c06\u7f51\u9875\u8f6c\u6362\u6210Android APP\uff0c\u6211\u4eec\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u5de5\u5177\uff1a<\/p>\n

– Android Studio\uff1a\u7528\u4e8e\u7f16\u5199Android APP\u7684\u5b98\u65b9\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002<\/p>\n

– Java\u6216Kotlin\u7f16\u7a0b\u8bed\u8a00\uff1a\u7528\u4e8e\u7f16\u5199Android APP\u7684\u7a0b\u5e8f\u4ee3\u7801\u3002<\/p>\n

– \u7f51\u7edc\u8fde\u63a5\uff1a\u7528\u4e8e\u8bbf\u95ee\u4f60\u7684Web App\u6216\u7f51\u7ad9\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Android\u9879\u76ee\uff1a\u6253\u5f00Android Studio\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Android\u9879\u76ee\uff0c\u547d\u540d\u4f60\u7684APP\uff0c\u5e76\u9009\u62e9\u4f60\u8981\u652f\u6301\u7684Android\u8bbe\u5907\u548c\u6700\u4f4eAPI\u7ea7\u522b\u3002<\/p>\n

3. \u8bbe\u7f6e\u5e03\u5c40\u6587\u4ef6\uff1a\u9ed8\u8ba4\u60c5\u51b5\u6839\u636eapp\u751f\u6210\u7f51\u9875\u7248<\/a>\u4e0b\uff0cAndroid Studio\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aactivity_main.xml\u7684\u5e03\u5c40\u6587\u4ef6\u3002\u6253\u5f00\u8be5\u6587\u4ef6\uff0c\u5728\u5176\u4e2d\u6dfb\u52a0WebView\u63a7\u4ef6\u3002\u4f8b\u5982\uff1a<\/p>\n

“`<\/p>\n<\/p>\n

android:id=”@+id\/webview”<\/p>\n

android:layoutapp\u751f\u6210\u5728\u7ebf<\/a>_width=”match_parent”<\/p>\n

android:layout_height=”match_parent” \/><\/p>\n

“`<\/p>\n

4. \u8bbe\u7f6e\u6743\u9650\uff1a\u4e3a\u4e86\u8ba9\u4f60\u7684APP\u80fd\u591f\u8bbf\u95ee\u4e92\u8054\u7f51\uff0c\u5728AndroidManifest.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0INTERNET\u6743\u9650\uff1a<\/p>\n

“`<\/p>\n<\/p>\n

“`<\/p>\n

5. \u8bbe\u7f6eWebView\uff1a\u5728MainActivity\uff08\u4e3b\u6d3b\u52a8\uff09\u4e2d\uff0c\u9996\u5148\u5bfc\u5165WebView\u76f8\u5173\u7684\u5305\uff1a<\/p>\n

“`<\/p>\n

import android.webkit.WebView;<\/p>\n

import android.webkit.WebViewClient;<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u5728onCreate()\u65b9\u6cd5\u4e2d\uff0c\u521d\u59cb\u5316\u5e76\u914d\u7f6eWebView\u63a7\u4ef6\uff1a<\/p>\n

“`<\/p>\n

WebView webView = findViewById(R.id.webview);<\/p>\n

webView.setWebViewClient(new WebViewClient());<\/p>\n

\/\/ \u542f\u7528JavaScript\u652f\u6301\uff08\u5982\u679c\u4f60\u7684Web App\u9700\u8981JavaScript\uff09<\/p>\n

webView.getSettings().setJavaScriptEnabled(true);<\/p>\n

\/\/ \u52a0\u8f7d\u5e76\u663e\u793a\u4f60\u7684\u7f51\u9875<\/p>\n

webView.loadUrl(“https:\/\/example.com”);<\/p>\n

“`<\/p>\n

6. \u5904\u7406\u8fd4\u56de\u952e\uff1a\u4e3a\u4e86\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u8fd4\u56de\u952e\u7684\u4e8b\u4ef6\u3002\u5f53\u7528\u6237\u6309\u4e0b\u8fd4\u56de\u952e\u65f6\uff0c\u5982\u679cWebView\u53ef\u4ee5\u540e\u9000\uff0c\u90a3\u4e48WebView\u5e94\u8be5\u540e\u9000\uff1b\u5426\u5219\uff0c\u5e94\u7528\u5e94\u8be5\u9000\u5230\u540e\u53f0\u3002\u5728MainActivity\u4e2d\uff0c\u8986\u76d6onBackPressed()\u65b9\u6cd5\uff1a<\/p>\n

“`<\/p>\n

@Override<\/p>\n

public void onBackPressed() {<\/p>\n

WebView webView = findViewById(R.id.webview);<\/p>\n<\/p>\n

if (webView.canGoBack()) {<\/p>\n

webView.goBack();<\/p>\n

} else {<\/p>\n

super.onBackPressed();<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

7. \u7f16\u8bd1\u548c\u8fd0\u884c\uff1a\u5728Android Studio\u4e2d\uff0c\u70b9\u51fb”Build”\u83dc\u5355\u4e0b\u7684”Make Project”\uff0c\u7136\u540e\u70b9\u51fb”Run”\u83dc\u5355\u4e0b\u7684”Run ‘app'”\uff0c\u5c06APP\u90e8\u7f72\u5230\u6a21\u62df\u5668\u6216\u771f\u5b9e\u8bbe\u5907\u4e0a\u3002<\/p>\n

\u73b0\u5728\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u5c06\u7f51\u9875\u6210\u529f\u8f6c\u6362\u4e3a\u4e86\u4e00\u4e2aAndroid\u539f\u751f\u5e94\u7528\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u8bb8\u591a\u8fdb\u9636\u529f\u80fd\u53ef\u4ee5\u5b9e\u73b0\uff0c\u4f8b\u5982\uff1a\u5904\u7406\u8bbe\u5907\u65cb\u8f6c\u3001\u6587\u4ef6\u4e0a\u4f20\u3001\u5b9a\u4f4d\u670d\u52a1\u3001\u63a8\u9001\u901a\u77e5\u7b49\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6df1\u5165\u7814\u7a76\u4e0b\u8fd9\u4e9b\u529f\u80fd\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06\u7f51\u9875\u751f\u6210APP\uff0c\u5373\u5c06\u7f51\u9875\u5e94\u7528\uff08Web App\uff09\u8f6c\u6362\u4e3a\u539f\u751f\u5e94\u7528\uff08Native App\uff09\u7684\u8fc7\u7a0b\u3002\u539f\u751f\u5e94\u7528\u6307\u7684\u662f\u4e13\u95e8\u4e3a\u67d0\u4e2a\u64cd\u4f5c\u7cfb\u7edf\uff08\u5982Android\u6216iOS\uff09\u8bbe\u8ba1\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u79cd\u8f6c\u6362\u53ef\u4ee5\u8ba9\u7528\u6237\u5728\u79fb\u52a8\u8bbe\u5907<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2325,989,9820,149,15424],"topic":[],"class_list":["post-14204","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-2325","tag-989","tag-app","tag-149"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/14204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=14204"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/14204\/revisions"}],"predecessor-version":[{"id":14381,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/14204\/revisions\/14381"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=14204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=14204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=14204"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=14204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}