Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between isNetworkUrl and isValidUrl

Tags:

java

android

I would like to know what is the difference between a URL and a Network URL.

public static boolean isNetworkUrl (String url)

public static boolean isValidUrl (String url)

http://developer.android.com/reference/android/webkit/URLUtil.html#isValidUrl%28java.lang.String%29

like image 595
psv Avatar asked May 26 '14 09:05

psv


1 Answers

Seeing the source code and documentation for both the functions:-

isValidUrl returns true if the url is a valid url of any url type(http url / file url etc).

  public static boolean isValidUrl(String url) {
      if (url == null || url.length() == 0) {
          return false;
      }

      return (isAssetUrl(url) ||
             isResourceUrl(url) ||
               isFileUrl(url) ||
               isAboutUrl(url) ||
             isHttpUrl(url) ||
             isHttpsUrl(url) ||
             isJavaScriptUrl(url) ||
            isContentUrl(url));
   }

Whereas isNetworkUrl returns true only if the url is a http / https url (i.e a network url adressing a network resource based on http protocol )

 public static boolean isNetworkUrl(String url) {
       if (url == null || url.length() == 0) {
            return false;
        }
        return isHttpUrl(url) || isHttpsUrl(url);
   }

Reference for source code:- http://www.grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/webkit/URLUtil.java#URLUtil.isNetworkUrl%28java.lang.String%29

Edit (20 june 2020): The url above is broken now, New url from official android pages:

like image 171
Mustafa sabir Avatar answered Nov 14 '22 22:11

Mustafa sabir