推荐安卓开发神器(里面有各种UI特效和android代码库实例)

/** * //检查网络 是否正常

  */

  private boolean checkNet(){

  ConnectivityManager manager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

  netWrokInfo = manager.getActiveNetworkInfo();

  if (netWrokInfo == null || !netWrokInfo.isAvailable()) {

  Toast.makeText(this, "当前的网络不可用,请开启网络", Toast.LENGTH_LONG).show();

  return false;

  }

  else if(netWrokInfo.getTypeName().equals("MOBILE")& netWrokInfo.getExt raInfo().equals("cmwap")){

  Toast.makeText(this, "cmwap网络不可用,请选择cmnet网络", Toast.LENGTH_LONG).show();

  return false;

  }else{

  return true;

  }

  }

  /**

  *Android 使用cmwap GPRS 方式联网

  */

  CMWAP和CMNET只是中国移动为其划分的两个GPRS接入方式。中国移动对CMWAP作了一定的限制,主要表现在CMWAP接入时只能访问 GPRS网络内的IP(10.*.*.*),而无法通过路由访问Internet,我们用CMWAP浏览Internet上的网页 就是通过WAP网关协议或它提供的HTTP代理服务实现的。 因此,只有满足以下两个条件的应用 才能在中国移动的CMWAP接入方式下正常工作:

  1.应用程序 的网络请求基于HTTP协议。

  2.应用程序 支持HTTP代理协议或WAP网关协议。

  这也就是为什么我们的G1无法正常用CMWAP的原因。

  一句话:CMWAP是移动限制的,理论上只能上WAP网,而CMNET可以用GPRS浏览WWW

  方法一:

  URL url = new URL("http://10.0.0.172/img/baidu_logo.gif");

  HttpURLConnection conn = (HttpURLConnection) url.openConnection();

  conn.setRequestProperty("X-Online-Host", "www.baidu.com");

  conn.setDoInput(true);

  conn.connect();

  InputStream is = conn.getInputStream();

  bitmap = BitmapFactory.decodeStream(is);

  is.close();

  conn.disconnect();

  方法二:

  CODE:

  package org.apache.http.examp les.client;

  import org.apache.http.Header;import org.apache.http.HttpEntity;

  import org.apache.http.HttpHost;

  import org.apache.http.HttpResponse;

  import org.apache.http.client.HttpClient;

  import org.apache.http.client.methods.HttpGet;

  import org.apache.http.conn.params.ConnRoutePNames;

  import org.apache.http.impl.client.DefaultHttpClient;

  import org.apache.http.util.EntityUtils;

  public class ClientExecuteProxy {

  public static void main(String [] args)throws Exception {

  HttpHost proxy = new HttpHost( "10.0.0.172", 80, "http");

  HttpHost target = new HttpHost("YOUR_TARGET_IP", 80, "http");

  DefaultHttpClient httpclient = new DefaultHttpClient();

  httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

  HttpGet req = new HttpGet("/");

  System.out.println("executing request to " + target + " via " + proxy);

  HttpResponse rsp = httpclient.execute(target, req);

  HttpEntity entity = rsp.getEntity();

  System.out.println("----------------------------------------");

  System.out.println(rsp.getStatusLine());

  Header[] headers = rsp.getAllHeaders();

  for (int i = 0; i< i++)>

  System.out.println(headers);

  }

  System.out.println("----------------------------------------");

  if (entity != null) {

  System.out.println(EntityUtils.toString(entity));

  }

  // When HttpClient instance is no longer needed,

  // shut down the connection manager to ensure

  // immediate deallocation of all system resources

  httpclient.getConnectionManager().shutdown();

  }

  }

更多相关文章

  1. Android Studio 实现播放本地/网络视频
  2. Android中检测网络连接状况的方法
  3. android中判断网络是否连接
  4. [置顶] Android 网络连接--Wifi/3G
  5. Android访问网络,使用HttpURLConnection还是HttpClient?
  6. Android : 网络版学生系统
  7. Android中使用Tcpdump抓取网络数据包
  8. Android 网络通信——HttpClient

随机推荐

  1. 中国编程第一人,一人抵一城!
  2. xabbix流程(续)
  3. 面试官不讲码德,问我Chrome浏览器的渲染原
  4. 漫画:什么是 “智能供应链” ?
  5. 漫画设计模式:什么是 “职责链模式” ?
  6. 配置vscode的cmder的方法
  7. 前端杂记-环境搭建
  8. mysql 存在更新 不存在插入
  9. mysql创建存储过程失败1307错误解决
  10. 0506作业