本文介绍了为什么CordovaWebViewClient不再在Cordova 6中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了自定义的webviewclient类,以覆盖Cordova 3.7中的onPageStarted, onPageFinished etc,它工作正常.

I have written custom webviewclient class to override onPageStarted, onPageFinished etc in cordova 3.7 which was working fine.

在以下代码中,我已将www目录托管到Web服务器,并从那里托管了cordova插件(条形码扫描仪,nfc,蓝牙等).

In following code is I have hosted the www directory to web server and interacting cordova plugins from there (barcodescanner, nfc, bluetooth etc).

public class MainActivity extends CordovaActivity {
    private WebView webView;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        super.init();

        loadUrl("https://example.com");
    }

    public class CustomCordovaWebViewClient extends CordovaWebViewClient {

        public CustomCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
            super(cordova, view);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            Log.i("CSP Log", "onPageStarted: " + url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            Log.i("CSP Log", "onPageFinished: " + url);
        }

        @Override
        public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
            super.doUpdateVisitedHistory(view, url, isReload);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }

    }

}

一年后,我将项目从cordova 3.7迁移到了cordova 6,但是我发现上面的代码像CordovaWebViewClient, super.onPageStarted etc一样无法解析符号.我也尝试过CordovaWebViewImpl并迷惑了自己.

After a year, I have migrated project from cordova 3.7 to cordova 6 but I found above code broken like CordovaWebViewClient, super.onPageStarted etc can't resolve symbols. I also tried CordovaWebViewImpl and confused myself.

在Google上搜索了很多之后,我发现了大多数在2011-14年给出的不适用的解决方案.我找不到Cordova文档有帮助.

After searching alot on google I found solution which were mostly given in 2011-14 which are not applicable. I couldn't found cordova docs helpful.

推荐答案

已由SystemWebViewClient

您应该执行以下操作:

SystemWebView wv = (SystemWebView)appView.getView();
wv.setWebViewClient(new SystemWebViewClient((SystemWebViewEngine)appView.getEngine()){
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        Log.i("CSP Log", "onPageStarted: " + url);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        Log.i("CSP Log", "onPageFinished: " + url);
    }

    @Override
    public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
        super.doUpdateVisitedHistory(view, url, isReload);
    }

    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        super.onReceivedError(view, errorCode, description, failingUrl);
    }
});

这篇关于为什么CordovaWebViewClient不再在Cordova 6中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:10