How to check if URL is valid in Android

kidalex picture kidalex · Feb 5, 2011 · Viewed 90.6k times · Source

Is there a good way to avoid the "host is not resolved" error that crashes an app? Some sort of a way to try connecting to a host ( like a URL ) and see if it's even valid?

Answer

dd619 picture dd619 · Dec 18, 2012

Use URLUtil to validate the URL as below.

 URLUtil.isValidUrl(url)

It will return True if URL is valid and false if URL is invalid.