Android使用HttpClient下载图片(2)

@Override
  protected Boolean doInBackground(String... params) {
   // TODO Auto-generated method stub
   System.out.println("[downloadImageTask->]doInBackground "
     + params[0]);
   // try {
   // mDownloadImage = HttpUtils.getNetWorkBitmap(params[0]);
   // } catch (MalformedURLException e) {
   // // TODO Auto-generated catch block
   // e.printStackTrace();
   // } catch (IOException e) {
   // // TODO Auto-generated catch block
   // e.printStackTrace();
   // }
   try {
    mDownloadImage = HttpUtils.getHttpGetBitmap(params[0]);
   } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   return true;
  }

// 下载完成回调
  @Override
  protected void onPostExecute(Boolean result) {
   // TODO Auto-generated method stub
   image.setImageBitmap(mDownloadImage);
   System.out.println("result = " + result);
   super.onPostExecute(result);
  }

// 更新进度回调
  @Override
  protected void onProgressUpdate(Integer... values) {
   // TODO Auto-generated method stub
   super.onProgressUpdate(values);
  }

}
}

如果图片较大可能会下载失败

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/61c8b7d014c10021b4c90fd34af0847e.html