Sample Code:
String url="http://sports.in.msn.com/football-world-cup-2014/world-cup-animals-5";String hostName=getDomainName(url);
private CharSequence getDomainName(String shareURL) throws URISyntaxException {
URI uri = new URI(shareURL);
String domain = uri.getHost();
return domain;
}
above method return host name from given URL.
You can get more from URL using below methods.
uri.getProtocol();
uri.getAuthority();
uri.getHost();
uri.getPort();
uri.getPath();
uri.getQuery();
uri.getFile();
Output:
protocol = httpauthority = sports.in.msn.com host = sports.in.msn.com port = -1 path = /football-world-cup-2014/world-cup-animals-5 query = null filename = /football-world-cup-2014/world-cup-animals-5
Comments
Post a Comment