【问题标题】:Detect if specified url is an image in Android?检测指定的 url 是否是 Android 中的图像?
【发布时间】:2011-03-28 02:06:17
【问题描述】:

如何快速检测指定URL是否包含Android中的图像?

我有 http://foo.bar/w23afv 类型的链接,所以像检查 URL 字符串结尾这样的幼稚方法在这里不起作用。

【问题讨论】:

    标签: android image http url


    【解决方案1】:

    检查 HTTP Content-Type 响应标头是否以 image/ 开头。

    URLConnection connection = new URL("http://foo.bar/w23afv").openConnection();
    String contentType = connection.getHeaderField("Content-Type");
    boolean image = contentType.startsWith("image/");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多