Getting WiFi proxy settings in Android

前端 未结 4 1130
天涯浪人
天涯浪人 2020-12-08 06:00

I am trying to read WIFI proxy settings

  • Proxy host
  • Proxy port
  • Proxy user (authentication)
  • Proxy password (authentication)
4条回答
  •  孤城傲影
    2020-12-08 06:13

    Following is code snippet to retrieve proxy details

    public static String getProxyDetails(Context context) {
            String proxyAddress = new String();
            try {
                if (IsPreIcs()) {
                    proxyAddress = android.net.Proxy.getHost(context);
                    if (proxyAddress == null || proxyAddress.equals("")) {
                        return proxyAddress;
                    }
                    proxyAddress += ":" + android.net.Proxy.getPort(context);
                } else {
                    proxyAddress = System.getProperty("http.proxyHost");
                    proxyAddress += ":" + System.getProperty("http.proxyPort");
                }
            } catch (Exception ex) {
                //ignore
            }
            return proxyAddress;
        }
    

    It'll return enmpty if some exception or no proxy detected;

提交回复
热议问题