在 webview 中使用 AngularJS 的 Android 应用程序

标签 android hybrid-mobile-app

如何使用 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/

相关文章:

android - Multi Flavor 应用中,如何避免重复资源

android - 将搜索功能添加到我的应用程序的最佳解决方案

flutter - Getx Flutter - 更新列表中的项目不是 react 性的

cordova - 对于 iOS,当设备处于横向(水平翻转)时强制方向为纵向

android - 使用基于Cordova框架开发的混合应用程序打开默认邮件应用程序

javascript - 在编辑模式下执行 CRUD 操作时选择 ionic 选择选项

android - MpAndroidChart Line 第一次绘制不正确

java - Android 上隐藏键盘会导致应用程序崩溃

android - 以编程方式将借记卡或信用卡添加到 Google 电子钱包

android - 无法在真实设备 Android 中运行 IBM Worklight 应用程序