【发布时间】:2010-11-18 19:39:17
【问题描述】:
标题很清楚。
以下代码...:
URL imageUrl = new URL(url);
try {
HttpURLConnection conn= (HttpURLConnection)imageUrl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
InputStream is = conn.getInputStream();
return BitmapFactory.decodeStream(is);
} catch (IOException e) {
e.printStackTrace();
}
如果 url 不包含文件格式将失败。例如,某些由 google 托管的图像会显示图像,但在 url 中没有文件格式(.png、.jpg 等)。
因此,url 连接的 content-type 标头返回“text/html”。我相信这是问题所在。
我尝试设置一个新的内容类型标头,但这似乎没有任何改变。
有人知道解决方法吗?
谢谢。
【问题讨论】:
-
你能举一个失败的例子吗?
标签: java android image httpurlconnection filenotfoundexception