Android Phonegap - TIMEOUT ERROR when trying to set a WebViewClient

后端 未结 3 621
再見小時候
再見小時候 2020-12-29 01:02

I\'m working with Android and Phonegap, and at the moment I\'m having trouble with one simple thing. I need to setup a webViewClient to the PhoneGap webView in order to capt

相关标签:
3条回答
  • 2020-12-29 01:25

    To accomplish what you want to do I would extend the CordovaWebViewClient class and override the methods you want but don't forget to call the super methods or PhoneGap won't work without the CordovaWebViewClient as it is an important class.

    0 讨论(0)
  • 2020-12-29 01:29

    I think I've figured this out on latest Cordova versions (I'm using 2.2). It fails at onPageStarted() because it's expecting an appView, which is null. Setting the appView seems to fix it eg

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.init();
    
        CordovaWebViewClient webViewClient = new CustomAcceptingWebViewClient(this);
        webViewClient.setWebView(this.appView);
        this.appView.setWebViewClient(webViewClient);
    
        super.loadUrl("file:///android_asset/www/index.html");
    
    }
    

    Note that the super.init() is also needed

    0 讨论(0)
  • 2020-12-29 01:32

    You forgot to call super ;)

        // Assign webclient.
        this.appView.setWebViewClient(new CordovaWebViewClient(me, this.appView) {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
    
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });
    
    0 讨论(0)
提交回复
热议问题