1

I have a WebView in which I load a webpage. In this webpage the user needs to do some actions. A specific action needs to be executed when the user arrives on a specific webpage. This action should execute automatically.

How can I continuously check the current URL in the WebView and connect an action to a certain condition?

An example code is:

String url = wv.getUrl();
if (url.contains("string"))
{
    code = url.substring(url.lastIndexOf("value=") + 6);
    dialog.dismiss(); //action
}

However, where can I place this so it continuously checks the URL of the WebView? Any help is appreciated.

Shishdem
  • 499
  • 1
  • 5
  • 19

1 Answers1

4

You have,

 webView.setWebViewClient(new WebViewClient()
  {
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {               

        String url = webView.getUrl();
        if (url.contains("string"))
        {
           code = url.substring(url.lastIndexOf("value=") + 6);
           dialog.dismiss(); //action
        }
        return false;                            
    }
 }

Ref : http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,java.lang.String)

Bharath Mg
  • 1,117
  • 1
  • 9
  • 18
  • Thank you so much! However, this does not return me the url which I want to load but returns the current url, so prior to loading the destination url - which I want to retrieve... – Shishdem Mar 06 '15 at 14:45
  • Oh but your question was you wanted to know the current URL.. Take a look at onPageFinished too. http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageFinished(android.webkit.WebView,java.lang.String) – Bharath Mg Mar 06 '15 at 14:54
  • My bad! Sorry. I got it fixed now, completely missed onPageFinished. Thanks, I'll mark your answer as correct. – Shishdem Mar 09 '15 at 09:03