After referring many articles on SO and google, couldn't find a solution for my question.
The question is, am fetching the hostname in onPageFinished method of WebViewClient class. Problem arises when getHost() returns me the hostname multiple times. But I would like to have a SINGLE hostname.
For example: When I open bmw.com website, getHost() returns me www.bmw.com twice, and m.bmw.com thrice for the same webpage.
Tried with onPageStarted, but the result is similar.
Even tried WebChromeClient to get the title, but can't rely as sometimes it doesn't return a title.
Is there a way to get a SINGLE hostname after the page loads?
Here is my code
public void onPageFinished(WebView view, String url4){
String urlHost = null;
try {
urlHost = new URL(url4).getHost().toString();
} catch (MalformedURLException e) {
e.printStackTrace();
}
addressBarTextView.setText(urlHost);
}
Fist a couple of observations:
That being said there are a couple of things you could do:
"m.*" -> "www.*"
), if you do this I'd recommend having some option for the user to see the 'real' URL too.