2015-05-08 Android►HttpClient 判断是否有网络 #欢迎来到风的博客 ###Android判断是否有网络12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758public class HttpUtils { /** * 判断是否有网络 * @param context * @return */ public static boolean isNetWork(Context context){ //得到网络的管理者 ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if(info!=null){ return true; }else{ return false; } } /** * 获取数据 * @param path * @return */ public static byte[] getData(String path) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(path); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200) { InputStream inputStream = response.getEntity().getContent(); byte[] buffer = new byte[1024]; int temp = 0; while ((temp = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, temp); outputStream.flush(); } } return outputStream.toByteArray(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }} Newer 判断sdCard是否挂载 Older 重写listview,使其嵌套scrollview