Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why CordovaWebViewClient not working in Cordova 6 anymore

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

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);
        }

    }

}

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.

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.

like image 304
mumair Avatar asked May 25 '16 08:05

mumair


People also ask

Does Cordova support Android 12?

We have integrated the Android 12 SplashScreen API including the compatibility library into the core of the Cordova-Android platform to provide support for Android API 22+. For more information, please refer to the PR and Cordova Docs.

What browser does Cordova use?

Actually it is Chrome, but a different version from the Chrome App.


2 Answers

It was replaced by SystemWebViewClient

You should do something like this:

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);
    }
});
like image 74
jcesarmobile Avatar answered Sep 30 '22 02:09

jcesarmobile


Cordova 4 removed the CordovaWebViewClient : look here

You may use WebViewClient instead of CordovaWebViewClient (The cordova-plugin-inappbrowser plugin use that for override onPageStarted event).

public class CustomCordovaWebViewClient extends WebViewClient
like image 31
Frix33 Avatar answered Sep 30 '22 01:09

Frix33