工具代码


 public class AsyncUploadImage extends AsyncTask<Object, Object, Object> {private static final String TAG = "AsyncUploadImage ";ImageView iv;private HttpURLConnection connection;private InputStream is;private Bitmap bitmap;public AsyncUploadImage(ImageView mImageView) {iv = mImageView;}@Overrideprotected Object doInBackground(Object... params) {URL url;try {url = new URL((String) params[0]);connection = (HttpURLConnection) url.openConnection();connection.setDoInput(true);connection.connect();is = connection.getInputStream();bitmap = BitmapFactory.decodeStream(is);is.close();} catch (Exception e) {e.printStackTrace();} finally {try {if (is != null) {is.close();}if (connection != null) {connection.disconnect();}} catch (IOException e) {e.printStackTrace();}}return bitmap;}@Overrideprotected void onPostExecute(Object result) {super.onPostExecute(result);if (null != result) {iv.setImageBitmap((Bitmap) result);Log.i(TAG, "image download ok!!!");}else {iv.setBackgroundResource(R.drawable.shuben1);Log.i(TAG, "image download false!!!");}}}

具体使用的代码

 new AsyncUploadImage(itemIcon).execute("http://temp/file/book/images/1325310017.jpg");//http://temp/file/book/images/1325310017.jpg  -> (this is your image url..)





更多相关文章

  1. Android网格布局实现--recyclerview
  2. Android(安卓)代码混淆异常 transformClassesAndResourcesWithPr
  3. Android(安卓)Studio 编译不通过,报错“找不到org.apache.http。
  4. Android动态刷新listview中的数据
  5. android 数据库工具类MyDbHelper
  6. android WiFi 开关代码
  7. 箭头函数的基础使用
  8. NPM 和webpack 的基础使用
  9. Python list sort方法的具体使用

随机推荐

  1. Android项目Android(安卓)Studio目录结构
  2. Android:控件GridView的使用
  3. Android——消息机制
  4. Android事件分发机制总结
  5. 【Android】Android(安卓)SDK下载和更新
  6. android之Uri的使用简介\Uri与path相互
  7. 基于Android(安卓)Volley的网络请求工具
  8. android 自定义对话框
  9. android异步更新UI
  10. 关于android WebViewClient和WebChromeCl