Android 判断网络是不是代理了

634 阅读1分钟
private static boolean isProxy() {
    boolean IS_ICS_OR_LATER = VERSION.SDK_INT >= 14;
    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 {
        Context ctx = getApplication().getApplicationContext();
        proxyAddress = Proxy.getHost(ctx);
        proxyPort = Proxy.getPort(ctx);
    }

    return !TextUtils.isEmpty(proxyAddress) && proxyPort != -1;
}