Wap proxy settings for android networks (China Telecom, China Mobile, and China Unicom)

Source: Internet
Author: User

The Code is as follows. The embedded program is available!


/**
* Proxy settings for image download;
* Get the HttpURLConnection of the dynamic proxy
* @ Param url: the url of the request;
* @ Return HttpURLConnection can be used for direct data operations;
* @ Throws IOException
*
* Set proxy
* Set the header
* Set the connection;
* Set the statistical time;
*/
Public HttpURLConnection getDynamicNetWorkHttpURLConnection (HttpURLConnection httpURLConnection, String url) throws IOException {

URL mURL = new URL (url );
If (DynamicNetWork. mConnectType = 0 ){

If (mCurrentApnName = null ){
MCurrentApnName = getCurrentApnInUse (context );
}

/** Mobile proxy connection */
If (mCurrentApnName. startsWith (CMWAP )){
String mDomainName = getDomainName (url );
Url = url. replace (mDomainName, mWAPLocalHost );
HttpURLConnection = (HttpURLConnection) mURL. openConnection ();
HttpURLConnection. setRequestProperty ("X-Online-Host", mDomainName );
/** Unicom proxy connection */
} Else if (mCurrentApnName. startsWith (UNIWAP) | mCurrentApnName. startsWith (G3WAP )){
InetSocketAddress inetAddress = new InetSocketAddress (mWAPLocalHost, 80 );
Java.net. Proxy. Type proxyType = java.net. Proxy. Type. valueOf (mURL. getProtocol (). toUpperCase ());
Java.net. Proxy javaProxy = new java.net. Proxy (proxyType, inetAddress );
HttpURLConnection = (HttpURLConnection) mURL. openConnection (javaProxy );
} Else/** proxy connection for telecom */
If (mCurrentApnName. startsWith (CTWAP )){
InetSocketAddress inetAddress = new InetSocketAddress (mcmalocalhost, 80 );
Java.net. Proxy. Type proxyType = java.net. Proxy. Type. valueOf (mURL. getProtocol (). toUpperCase ());
Java.net. Proxy javaProxy = new java.net. Proxy (proxyType, inetAddress );
HttpURLConnection = (HttpURLConnection) mURL. openConnection (javaProxy );
}
} Else {
HttpURLConnection = (HttpURLConnection) mURL. openConnection ();
}
HttpURLConnection. connect ();
Return httpURLConnection;
}

/** Get the current network name;
* @ Param mcontext
* @ Return
*/
Public static String getCurrentApnInUse (Context mcontext ){
String name = "no ";
ConnectivityManager manager = (ConnectivityManager) mcontext. getSystemService (Context. CONNECTIVITY_SERVICE );
Try {
NetworkInfo activeNetInfo = manager. getActiveNetworkInfo ();
If (activeNetInfo! = Null & activeNetInfo. isAvailable ()){
Name = activeNetInfo. getExtraInfo ();
}
} Catch (Exception e ){
E. printStackTrace ();
}
Return name;
}


/** Get the current proxy
* @ Param currentName
* @ Return
*/
Public static String getApnProxy (String currentName ){
If ("". equals (currentName) | null = currentName ){
Return "";
}
CurrentName = currentName. toLowerCase ();
If (currentName. startsWith (CMWAP) | currentName. startsWith (UNIWAP) | currentName. startsWith (G3WAP ))
Return CMCC_WAPPROXY;
Else if (currentName. startsWith (CTWAP ))
Return CMCC_CDMAPROXY;
Else
Return "";

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.