2

What I have: I have a WebView. I am loading an HTML file in it. There is a button in that HTML.

What I want: I want to intercept the click of that HTML button. Lets say there is an email scheme in that URL. I want to intercept the request so that I can extract the email information (i.e. Subject, Body etc) and open an Email Client before loading the page actually.

What is the problem: I can't figure out on how to get the URL and filter it on HTML button click. There should be an event which should be fired whenever we make any request from WebView. Please guide on how to achieve this task.

Khawar
  • 5,197
  • 4
  • 28
  • 52
  • 1
    If you know what to intercept - use WebViewClient and override shouldOverrideUrlLoading(WebView wv, String url), parse url and if need - start new intent. – Vyacheslav Shylkin Feb 29 '12 at 14:23
  • I have already used it but it doesn't get into the function "shouldOverrideUrlLoading". May be because I am having the button in HTML? – Khawar Mar 01 '12 at 08:08
  • http://stackoverflow.com/questions/6738328/shouldoverrideurlloading-in-webview-for-android-not-running – Vyacheslav Shylkin Mar 01 '12 at 08:56

1 Answers1

1

First of all as you are using html, you should check whether java script is enabled or not

myWebView.getSettings().setJavaScriptEnabled(true);

secondly you can use

myWebView.setWebViewClient(new WebViewClient()
  {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

When you hit a url it will take you to this function shouldOverrideUrlLoading where you can call an intent or do anything you want

Rajeel
  • 384
  • 2
  • 7