直接贴代码

public class HttpClientImageDownloader extends BaseImageDownloader implementsImageDownloader {public HttpClientImageDownloader(Context context) {super(context);}@Overrideprotected InputStream getStreamFromFile(String imageUri, Object extra)throws IOException {String filePath = Scheme.FILE.crop(imageUri);File file = new File(filePath);if(!file.exists())file.createNewFile();return new ContentLengthInputStream(new BufferedInputStream(new FileInputStream(filePath), BUFFER_SIZE),(int) new File(filePath).length());}@SuppressLint("UseValueOf")@Overrideprotected InputStream getStreamFromNetwork(String imageUri, Object extra)throws IOException {//HttpURLConnection conn = createConnection(imageUri, extra);////int redirectCount = 0;//while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {//conn = createConnection(conn.getHeaderField("Location"), extra);//redirectCount++;//}//EOFException来自conn.getResponseCode()//InputStream imageStream;//try {//imageStream = conn.getInputStream();//} catch (IOException e) {//// Read all data to allow reuse connection (http://bit.ly/1ad35PY)//IoUtils.readAndCloseStream(conn.getErrorStream());//throw e;//}DefaultHttpClient client = new DefaultHttpClient();HttpGet request = new HttpGet(imageUri);request.getParams().setParameter("http.socket.timeout",new Integer(connectTimeout));request.addHeader("Pragma", "no-cache");request.addHeader("Cache-Control", "no-cache");request.addHeader("Charset", "UTF-8");HttpResponse httpResponse = client.execute(request);HttpEntity entity = httpResponse.getEntity();InputStream imageStream = entity.getContent();return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), (int)entity.getContentLength());}}
另外配置为自己的imageloader
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).defaultDisplayImageOptions(defaultOptions).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().threadPoolSize(3).imageDownloader(new HttpClientImageDownloader(this )).tasksProcessingOrder(QueueProcessingType.LIFO).memoryCache(new WeakMemoryCache()).build();


更多相关文章

  1. Android:使用SpannableString实现图片替换相应的文字
  2. Android(安卓)代码生成界面Sample
  3. Android(安卓)中保存图片的代码
  4. android maxLines ellipsize 配合使用失效,解决办法
  5. Android弹出对话框简单代码
  6. Android中将Activity转换成View使用.
  7. android计算器简单版【安卓进化一】
  8. android 代码创建快捷方式
  9. Android分享功能

随机推荐

  1. Android全局主题样式控制,语言设置、主题
  2. 启动android默认浏览器
  3. android 9.0 设置 应用应用信息 隐藏 app
  4. Android隐式启动Activity可能存在的坑
  5. 设置ListView分割线
  6. Android 7.1 触摸事件代码跟踪
  7. android各版本对应的SDK level(包括androi
  8. [Android 特效] Android 通过流播放声音(
  9. Android写Logcat文件保存到SD卡
  10. android用Popup弹出窗(PopupWindow的使用