如何使用 AngularJS 和 H5 构建 Android native /混合应用程序,而不使用 PhoneGap 或 Cordova,只需在 Android 布局文件中使用简单的 WebView。
请提供一些引用:)
最佳答案
任何 AngularJS Web 应用程序都可以在 WebView
中正常运行。
要在 WebView
中运行网站,您所需要做的就是这样。
final WebView containerWbVw = findViewById(R.id.fragment_wbVw_container_id);
WebSettings webSettings = containerWbVw.getSettings();
webSettings.setJavaScriptEnabled(true);
containerWbVw.setWebChromeClient(new WebChromeClient());
然后使用
在WebView
中加载URL
containerWbVw.loadUrl(WEBAPP_URL);
WEBAPP_URL
可以是 Assets 文件夹中的 HTML 页面,也可以是托管在服务器上的 HTML 页面
//assets folder file
WEBAPP_URL = "file:///android_asset/main.html";
//server link
WEBAPP_URL="https://mysite.mycompany.com/myapp";
除此之外,您还需要与 native Android 应用程序交互以发送和接收数据。例如,一个用例是使用设备的相机获取扫描的条形码。为此,您需要 Javasrcript Bridge .
关于在 webview 中使用 AngularJS 的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40810646/