标签:
try { URL url = new URL(path); //path图片的网络地址 HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){ Bitmap bitmap = BitmapFactory.decodeStream(httpURLConnection.getInputStream()); imageview.setImageBitmap(bitmap);//加载到ImageView上 System.out.println("加载网络图片完成"); }else{ System.out.println("加载网络图片失败"); } } catch (IOException e) { e.printStackTrace(); }
今天想在Android下,用httpClient去获取网页的内容,结果在httpClient处报了错
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public static String getHtmlByUrl(String url){
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
HttpHost proxy = new HttpHost(PROXY, PROXY_PORT);
DefaultHttpClient httpClient = new DefaultHttpClient();
在httpClient访问前,加上红颜色的代码。
方法二:
用java创建个线程,在线程中去httpClient访问网络。
android下的android.os.StrictMode$AndroidBlockGuardPo
标签:
原文地址:http://my.oschina.net/u/1866821/blog/364661