0
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public void helperConnect(final ScanResult scanResult) {
    try {

        Log.v("rht", "Item clicked, SSID " + scanResult.SSID + " Security : " + scanResult.capabilities);

        conf = new WifiConfiguration();

        networkSSID = scanResult.SSID;

        wifiEnterpriseConfig = new WifiEnterpriseConfig();
        conf.SSID = "\"" + networkSSID + "\"";   // Please note the quotes. String should contain ssid in quotes
        conf.status = WifiConfiguration.Status.ENABLED;
        conf.priority = 40;

        if (scanResult.capabilities.toUpperCase().contains("EAP")) {
            Log.v("EAP", "Configurando EAP");

            conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
            conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);

            wifiEnterpriseConfig.setIdentity(networkIdentity);
            wifiEnterpriseConfig.setPassword(networkPass);
            wifiEnterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PEAP);
            wifiEnterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);

            conf.enterpriseConfig = wifiEnterpriseConfig;

        }

        int networkId = wifiManager.addNetwork(conf);

        //setWifiProxySettings(); ESTA SERIA LA FUNCION DE CONFIGURACION DEL PROXY

        Log.v("rht", "Add result " + networkId);

        boolean isDisconnected = wifiManager.disconnect();
        Log.v("rht", "isDisconnected : " + isDisconnected);

        boolean isEnabled = wifiManager.enableNetwork(networkId, true);
        Log.v("rht", "isEnabled : " + isEnabled);

        boolean isReconnected = wifiManager.reconnect();
        Log.v("rht", "isReconnected : " + isReconnected);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Quiero saber como es que se configura el proxy para poder conectarme. Gracias

2
  • Dele un vistazo a esta respuesta de SO Commented el 15 may. 2018 a las 15:38
  • @J.Rodríguez esa respuesta ya la habia visto y no aparece como configurar el proxy de la red... que es lo que quiero. Lo mismo que haces cuando vas a ajustes -> wifi y sacas el context menu y le das modificar red te sale la opcion Opciones Avanzadas y puedes modificar el proxy y otros ajustes eso es lo q necesito saber, como modificarlos desde codigo
    – Alex Rivas
    Commented el 15 may. 2018 a las 16:04

1 respuesta 1

0

A quien pueda interesar.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("unchecked")
private static WifiConfiguration setProxy(WifiConfiguration conf, String hostname, int port, List<String> bypass, PROXY_TYPE type) {
    try {
        //linkProperties is no longer in WifiConfiguration
        Class proxyInfoClass = Class.forName("android.net.ProxyInfo");
        Class[] setHttpProxyParams = new Class[1];
        setHttpProxyParams[0] = proxyInfoClass;
        Class wifiConfigClass = Class.forName("android.net.wifi.WifiConfiguration");
        Method setHttpProxy = wifiConfigClass.getDeclaredMethod("setHttpProxy", setHttpProxyParams);
        setHttpProxy.setAccessible(true);

        //Get the ENUM ProxySettings in IpConfiguration
        Class ipConfigClass = Class.forName("android.net.IpConfiguration");
        Field f = ipConfigClass.getField("proxySettings");
        Class proxySettingsClass = f.getType();

        Class[] setProxySettingsParams = new Class[1];
        setProxySettingsParams[0] = proxySettingsClass;
        Method setProxySettings = wifiConfigClass.getDeclaredMethod("setProxySettings", setProxySettingsParams);
        setProxySettings.setAccessible(true);


        ProxyInfo pi = null;
        String Type = null;
        switch (type) {
            case MANUAL:
                Type = "STATIC";
                pi = ProxyInfo.buildDirectProxy(hostname, port, bypass);
                break;

            case PAC_URL:
                Type = "PAC";
                pi = ProxyInfo.buildPacProxy(Uri.parse(hostname));
        }

        //pass the new object to setHttpProxy
        Object[] params_SetHttpProxy = new Object[1];
        params_SetHttpProxy[0] = pi;
        setHttpProxy.invoke(conf, params_SetHttpProxy);

        //pass the enum to setProxySettings
        Object[] params_setProxySettings = new Object[1];
        params_setProxySettings[0] = Enum.valueOf((Class<Enum>) proxySettingsClass, Type);
        setProxySettings.invoke(conf, params_setProxySettings);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return conf;
}

Con este codigo pude modificar el proxy de una conexion wifi.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.