Recently received demand, it is necessary to implement the function of preventing friends from capturing packets.
Start to do it: by judging the current network status, judging whether the current network is configured with an agent
directly upload the code:
/**
* 判断设备 是否使用代理上网
* @param context 上下文对象
* return 当前网络是否开启了代理
*/
public static boolean isWifiProxy(Context context) {
final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
String proxyAddress;
int proxyPort;
if (IS_ICS_OR_LATER) {
proxyAddress = System.getProperty("http.proxyHost");
String portStr = System.getProperty("http.proxyPort");
proxyPort = Integer.parseInt((portStr != null ? portStr : "-1"));
} else {
proxyAddress = android.net.Proxy.getHost(context);
proxyPort = android.net.Proxy.getPort(context);
}
return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1);
}
Check whether the proxy
is enabled during the network request of the project. If the proxy is turned on, do not request the network or directly guide the offline function. It is
for reference only