isNetworkUrl和isValidUrl之间的区别

时间:2014-05-26 09:15:19

标签: java android

我想知道网址和网络网址之间的区别。

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

1 个答案:

答案 0 :(得分:8)

查看这两个函数的源代码和文档: -

如果url是任何url类型的有效url(http url / file url等),则

isValidUrl返回true。

  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));
   }

isNetworkUrl仅在url是http / https url(即基于http协议的网络资源的网络URL)返回true时才会返回

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

源代码参考: - 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