我建议询问图像请求的负责人,因为它更快。
非毕加索:
HttpClient client= new DefaultHttpClient();
HttpHead headMethod = new HttpHead(urlToImage);
HttpResponse response = client.execute(headMethod);
if(response.getStatusLine().getStatusCode== HttpStatus.SC_NOT_FOUND) {
// Image does not exist, show a placeholder or something
} else {
// load image into the view.
}
Run Code Online (Sandbox Code Playgroud)
Picasso :(与头部版本无关,但这是一个简单的替代方法来处理它,还可以查看毕加索可以用来微调成功/错误的回调)
Picasso.with(context).load(urlToImage).into(imageView).placeholder(R.drawable.user_placeholder).error(R.drawable.user_placeholder_error);
Run Code Online (Sandbox Code Playgroud)
参考:
来自 Android SDK 参考的 Apache HttpHead
来自 Android SDK 参考的 Apache HttpStatus
| 归档时间: |
|
| 查看次数: |
4443 次 |
| 最近记录: |