|
/**
*
* 判断是否使用移动电话网络
*
* @return
*/
public static boolean isMobileActive(Context ctx) {
ConnectivityManager cm =
(ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileNet = cm.getActiveNetworkInfo();
if (mobileNet != null
&& mobileNet.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
} else {
return false;
}
}
复制代码使用HttpClient的话:
HttpHost proxy;
String proxyHost = android.net.Proxy.getDefaultHost();
int proxyPort = android.net.Proxy.getDefaultPort();
if (proxyHost != null) {
proxy = new HttpHost(proxyHost, proxyPort);
mClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
}
复制代码使用HttpURLConnection的话:
if (isMobileActive(ctx)) { // mobile
String proxyHost = android.net.Proxy.getDefaultHost();
int proxyPort = android.net.Proxy.getDefaultPort();
if (proxyHost != null)
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
}
HttpURLConnection rs;
if (proxy != null) {
rs = (HttpURLConnection) url.openConnection(proxy);
}
复制代码使用webview的话:
oauth_web.enablePlatformNotifications();//cmwap代理
复制代码 |
|