cordova+APP+vue+ quasar 开发android安卓 APP时 WebView 里的常见问题及其解决方案汇总

问题一、cordova打包app,http图片显示不了,android不兼容http,https混合使用问题

  • 原因:Android5.0上 WebView中Http和Https混合问题
  • 解决:修改java代码,要修改的文件路径:src-cordova\platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemWebViewEngine.java
  • 要新增的代码块如下:
 * MIXED_CONTENT_ALWAYS_ALLOW:允许从任何来源加载内容,即使起源是不安全的;
 * MIXED_CONTENT_NEVER_ALLOW:不允许Https加载Http的内容,即不允许从安全的起源去加载一个不安全的资源;
 * MIXED_CONTENT_COMPATIBILITY_MODE:当涉及到混合式内容时,WebView 会尝试去兼容最新Web浏览器的风格。

 webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    private void initWebViewSettings() {
        webView.setInitialScale(0);
        webView.setVerticalScrollBarEnabled(false);
        // Enable JavaScript

        final WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
        // 新增的https&https混合使用模式
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

        String manufacturer = android.os.Build.MANUFACTURER;
        LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
    }

问题二、

发表评论 / Comment

用心评论~