deSelby
deSelby

Reputation: 1407

Android WebViewClient problem

I've defined a private class that extends WebViewClient and set my WebView's client to an instance of that class (webView01.setWebViewClient(new Callback());).

The class definition is as follows:

private class Callback extends WebViewClient {
    public void onLoadResource (WebView view, String url) {
    }
    public void onPageStarted (WebView view, String url, Bitmap favicon) {
    }
    public void onPageFinished (WebView view, String url) {
        Animation anim = AnimationUtils.loadAnimation(MyNews.this, R.anim.webviewanim);
        view.startAnimation(anim);
    }
    public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {
    }   
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        Log.e("loading url", url);
        return false;
    }
}

My problem is that onPageFinished is definitely getting called, but shouldOverrideUrlLoading is never being called.

What am I doing wrong here?

6/13/2010

A little more information.

I'm loading the initial page from a string ( webView01.loadDataWithBaseURL("fake://fake", myHTML, "text/html", "UTF-8", null); ).

The page loads (and there are several calls to onLoadResource) and onPageFinished is being called at page load completion.

When the user taps on an Anchor link in the page, instead of calling shouldOverrideUrlLoading, onLoadResource is called.

I need to invoke the full web browser when the user taps on the link, but I never get the chance to override url loading.

Upvotes: 1

Views: 2181

Answers (1)

Hakem Zaied
Hakem Zaied

Reputation: 14239

From what i have featured in webview till now, the shouldOverrideUrlLoading() doesn't get called when you call webview.load("website"), but if this website has redirection to another it works. So the work around is to do what you want to be done when you call webview.load("website") (like calling a function that writes to the log Log.e("loading url", url)) since you already know the url and what needs to be done, shouldOverrideUrlLoading() only intercepts the requests sent from the webview it self.

Hope i was helpful.

Upvotes: 1

Related Questions