Rectangle 27 0

android How do I verify if the url entered in my webview is valid and if not valid how do i redirect to some other url?


yourWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        // TODO Auto-generated method stub
        super.onReceivedError(view, errorCode, description, failingUrl);
    }
});

Also, I am not sure how to check the valididty of the search term, I can post more code if need be

I am using @Override public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) { Toast.makeText(view.getContext(), "Authentication Error", Toast.LENGTH_LONG).show(); super.onReceivedError(view, errorCode, description, failingUrl); } and as i mentioned it is not an authentication issue,page loads as expected but within the page the search term is not valid and hence the whole url loads the precondition thing which means te search term is invalid, so was wondering is there a way to redirect to other url if the search term is invlid

Please check the attached image, I have the function you mentioned in my code already.However it does not show the error as authentication error and displays the invalid url as precondition set as in my webview

You can use the Webview's WebViewClient to catch the error and do whatever you see convenient. Here is a sample:

onReceivedError is not called? Try to show a toast in there or log

Note