Skip to content Skip to sidebar Skip to footer

Webview.geturl() Returns Null Because Page Not Done Loading

I want to get the url of the webview. However, the method calls before the page is done loading so it always returns with null. Any way around this? Thanks. WebView webView = ne

Solution 1:

Try adding a WebViewClient and overriding the onPageFinished(...) method. I've never done it but something like this might work...

String theUrl;
WebView webView = newWebView(this);
setContentView(webView);

webview.setWebViewClient(newWebViewClient() {

    publicvoidonPageFinished(WebView view, String url) {
        theUrl = url;
    }

});

webView.loadUrl(myURL);

Solution 2:

Create a subclass of WebViewClient which overrides onPageStarted(webView, url, favicon) and set it to your WebView (using setWebViewClient()). You'll have the url of the page which is loading or displayed.

Post a Comment for "Webview.geturl() Returns Null Because Page Not Done Loading"