Reputation: 3529
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 = new WebView(this);
setContentView(webView);
webView.loadUrl(myURL);
//page is not done loading yet
String url = webView.getUrl(); //returns null
Upvotes: 2
Views: 8538
Reputation: 2094
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.
Upvotes: 2
Reputation: 48871
Try adding a WebViewClient
and overriding the onPageFinished(...)
method. I've never done it but something like this might work...
String theUrl;
WebView webView = new WebView(this);
setContentView(webView);
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
theUrl = url;
}
});
webView.loadUrl(myURL);
Upvotes: 3