标签:ace params style syn sync try connect image on()
private void loadImage(String url, final ImageView ivIcon){ new AsyncTask<String,Void,Bitmap>(){ @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); if(bitmap == null){ ivIcon.setImageResource(R.mipmap.ic_launcher); }else{ ivIcon.setImageBitmap(bitmap); } } @Override protected Bitmap doInBackground(String... params) { try { URL url = new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); int code = connection.getResponseCode(); if(code == 200){ InputStream is = connection.getInputStream(); return BitmapFactory.decodeStream(is); } } catch (Exception e) { e.printStackTrace(); } return null; } }.execute(url);
标签:ace params style syn sync try connect image on()
原文地址:http://www.cnblogs.com/yu12/p/7497263.html