1. How to Implement
1.1 using httpurlconnection
1.2 using HttpClient
1.3 using sockets, such as: pea pods, chat tools
2. Communication channels
2.1 WLAN (Wi-Fi), data transfer around the meter
2.2 Mobile APN access point (Base station)
2.2.1 Wap Way, Chinese characteristics, first will connect the carrier agent to intercept 10.0.0.172,httpurlconnection will be unstable
The 2.2.2 Net way
3. Communication tools
3.1 determine the network type
Depending on the context, determine whether WiFi or APN, and then determine the APN access method, There is proxy information is the WAP is not the net
Packagecom.tsh.lottery.net;ImportAndroid.content.ContentResolver;ImportAndroid.content.Context;ImportAndroid.database.Cursor;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;ImportAndroid.net.Uri; Public classNetUtils {/*** Get network status *@paramContext *@return */ Public StaticString Getnetworkinfo (context context) {Connectivitymanager cm=(Connectivitymanager) Context.getsystemservice (Context.connectivity_service); //Judging WiFiNetworkinfo networkinfo=Cm.getnetworkinfo (Connectivitymanager.type_wifi); if(networkinfo!=NULL&&networkinfo.isconnected ()) { return"WiFi"; } //determine APNNetworkinfo mobileinfo=Cm.getnetworkinfo (Connectivitymanager.type_mobile); if(mobileinfo!=NULL&&mobileinfo.isconnected ()) { //Access to APN access mode because of a permissions issue that did not succeed//contentresolver resolver=context.getcontentresolver ();//Cursor cursor=resolver.query (Uri.parse ("Content://telephony/carriers "), null , NULL, NULL, and NULL);//if (cursor!=null && Cursor.movetofirst ()) {//String proxy=cursor.getstring (Cursor.getcolumnindex ("proxy"));//System.out.println (proxy);// } return"Mobile"; } return"No"; }}
[Android] network link types and channels