Here is How to Get Host Domain from URL in Android Java

Sometimes, we might need extract domain name such as from the In android java, the code below can do it. It will output only the domain name after stripping other characters

Java Code for getting host domain name from URL

URI uri = null;
            try {
                uri = new URI(url);
                String domain = uri.getHost();
                Toast.makeText(mContext, domain, Toast.LENGTH_SHORT).show();
            } catch (URISyntaxException e) {


Post navigation


This site uses Akismet to reduce spam. Learn how your comment data is processed.