Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get current URL on click event of WebView in Android

    private WebView wv;
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.infoweblinkview);

    wv=(WebView) findViewById(R.id.weblinkview);
    wv.setWebViewClient(new WebViewClient());
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadUrl(getString(R.string.infourl));


 wv.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    String  previousUrl = wv.getUrl();
                }
            });

}
like image 1000
Prashant Kadam Avatar asked Jul 29 '11 04:07

Prashant Kadam


1 Answers

for that, your can override some method in your WebViewClient class

@Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

Use any of this method as per your requirement, the String url gives you the url

like image 66
Labeeb Panampullan Avatar answered Sep 29 '22 08:09

Labeeb Panampullan