标题已经很明确了。
以下代码...:
以下代码...:
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连接的内容类型标头返回“text/html”。我认为这是问题所在。
我尝试设置一个新的内容类型标头,但似乎没有改变任何东西。
有人知道解决方法吗?
谢谢。