1. Many people know that mobile provides two different access points, CMWAP and CMNET. The former is set up for mobile WAP to access the Internet, the latter is mainly for the use of GPRS internet services such as PCs, laptops, PDAs. There is no difference in their implementation methods, but because of their different positioning, CMWAP has some restrictions and their charges are also different compared with CMNET. We often say that monthly Internet access is a monthly wap. In order to distinguish between the two in applications, mobile imposes certain limitations on CMWAP, mainly because it can only access IP addresses in the GPRS network (10. *. *. *), but cannot access the Internet through routing. We use CMWAP to browse Web pages on the Internet through the WAP Gateway Protocol or its HTTP proxy service. That is, the only WAP gateway through the mobile GPRS network: 10.0.0.172. CMNET has full Internet access, which is not mentioned here. Let's take a look at CMWAP. With the limitations mentioned above, the application scope of CMWAP depends on the support provided by WAP Gateway. Currently, mobile WAP Gateway only provides HTTP Proxy protocol (port 80 and port 8080) and WAP Gateway Protocol (Port 9201 ).
Therefore, only applications that meet the following conditions can work normally in the mobile CMWAP access mode: 1. network requests of applications are based on the HTTP protocol. 2. Applications Support HTTP Proxy protocol or WAP gateway protocol. Cmnet is not restricted. In fact, access through cmwap requires a mobile gateway to connect through the http protocol. The consequence is that the speed slows down and the connection is through cmnet, is to directly connect to the server on the Internet, the speed will be faster than cmwap. Haha! I believe that all the friends who have already used it will feel the difference between the two.
To use cmwap, you need to set a proxy, but you do not need to use wifi or cmnet. Instead, you cannot read the data after setting the proxy. The method is as follows:
In Android, there are two different HttpClient classes,
One is HttpURLConnection in the Java.net package, which sets the Proxy Code as follows: proxy Proxy = new Proxy (java.net. Proxy. Type. HTTP, new InetSocketAddress ("10.0.0.172", 80 ));
HttpURLConnection connection = (HttpURLConnection) url. openConnection (proxy); another is Apache's HttpClient: DefaultHttpClient httpclient = new DefaultHttpClient (); HttpHost proxy = new HttpHost ("10.0.0.172", 80); httpclient. getParams (). setParameter (ConnRoutePNames. DEFAULT_PROXY, proxy );
How to Use CMWAP in Android
To access China Mobile's Wap network, you need to set the Proxy: Host: "10.0.0.172" Port: 80. In Android, there are two different HttpClient classes. One is HttpURLConnection in the Java.net package, it sets the Proxy Code as follows: proxy Proxy = new Proxy (java.net. proxy. type. HTTP, new InetSocketAddress ("10.0.0.172", 80); HttpURLConnection connection = (HttpURLConnection) url. openConnection (proxy); another is Apache's HttpClient: DefaultHttpClient httpclient = new DefaultHttpClient (); HttpHost proxy = new HttpHost ("10.0.0.172", 80); httpclient. getParams (). setParameter (ConnRoutePNames. DEFAULT_PROXY, proxy );
Obtain the network type and message, and check whether the network connection is wifi, cmnet in GPRS, or cmwap.
Private boolean getNetType (){
ConnectivityManager conn = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE );
If (conn = null) return false;
NetworkInfo info = conn. getActiveNetworkInfo ();
If (info = null) return false;
String type = info. getTypeName (); // MOBILE (GPRS); WIFI
Log. v ("tag", "NetworkType =" + type );
If (type. equals ("WIFI ")){
Return true;
} Else if (type. equals ("MOBILE ")){
String apn = getAPN (this );
Log. v ("tag", "APN =" + apn );
If (apn! = Null & apn. equals ("cmwap ")){
Return false;
} Else {
Return true;
}
}
Return false;
}
2. Check whether the network connection exists
Public static boolean isNetworkAvailable (Activity mActivity ){
Context context = mActivity. getApplicationContext ();
ConnectivityManager connectivity = (ConnectivityManager) context. getSystemService (Context. CONNECTIVITY_SERVICE );
If (connectivity = null ){
Return false;
} Else {
NetworkInfo [] info = connectivity. getAllNetworkInfo ();
If (info! = Null ){
For (int I = 0; I & lt; info. length; I ++ ){
If (info [I]. getState () = NetworkInfo. State. CONNECTED ){
Return true;
}
}
}
}
Return false;
}
3. Why does the android Access Point Add the APN)
In android development, use the following code to set the APN:
1. Step 1: Create an activity and set the APN using the following code:
ContentValues values = new ContentValues ();
Values. put ("NAME", "CMCC ");
Values. put ("APN", "CMCC ");
Values. put ("PROXY", "192.168.0.171 ″);
Values. put ("PORT", "80 ″);
Values. put ("USER", "");
Values. put ("PASSWORD", "");
This. getContentResolver (). insert (Uri. parse ("content: // telephony/carriers"), values );
2. Add the following content to AndroidManifest. xml: www.2cto.com
<Uses-permission android: name = "android. permission. WRITE_APN_SETTINGS"/>
Author: caikezhan