首先判断是Wifi还是Mobile,如果是Mobile 有两种,一种是cmwap,另一种是cmnet。如果是cmwap ,则需要设置代理才能连接。
ConnectivityManager conManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//mobile 3G Data Network State
mobile = conManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
//wifi State
wifi = conManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
ConnectivityManager conManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//mobile 3G Data Network State
mobile = conManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
//wifi State
wifi = conManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
取得网络链接
urlConn = (HttpURLConnection)url.openConnection(); //Wifi
//-----------cmwap-----------
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
urlConn = (HttpURLConnection)url.openConnection(proxy);
urlConn = (HttpURLConnection)url.openConnection(); //Wifi
//-----------cmwap-----------
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
urlConn = (HttpURLConnection)url.openConnection(proxy);
阅读(1706) | 评论(0) | 转发(0) |