1

In first place, I connect to the open Wifi programaticaly

public static boolean conectar(Context ctx, String user, String pass){

    boolean conectado = false;

    String networkSSID = "wifiguay.es";

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\"";   

    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); 
    wifiManager.addNetwork(conf);

    List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
    for( WifiConfiguration i : list ) {
        if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
             wifiManager.disconnect();
             wifiManager.enableNetwork(i.networkId, true);
             wifiManager.reconnect();               
             conectado = true;

             break;
        }           
    }

    return conectado;
}

Then, I detect if the open Wifi is "Wifiguay.es" and I open the browser to put the username and password.

public class ConexionEstablecida extends BroadcastReceiver  {

    public void onReceive(Context context, Intent intent) {

        NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if(info != null){
            if(info.isConnected()){
                WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                String ssid = wifiInfo.getSSID();
                String networkSSID = "wifiguay.es";

                if(ssid.equalsIgnoreCase("\"" + networkSSID + "\"")){
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://wifiguay.lan/login?dst=http%3A%2F%2Fwww.google.es%2F"));    
                    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(i);
                }
            }
        }
    }
}

Now, i don´t know how to do to put the data.

Dryken
  • 11
  • 1
  • 2

1 Answers1

0

You can take a look at this question, you'll have to customize it for your needs, namely changing the field names.

Also, I don't know if this applies to your situation, but storing sensitive passwords is "tricky" at best, maybe consider simply opening the browser and letting the user (or the browser if it's setup to save credentials) take care of entering the password.

Edit: The example from that question:

mWebView.loadUrl(url);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
    String user="u";
    String pwd="p";
    view.loadUrl("javascript:document.getElementById('nameofyourusernamefield').value = '"+user+"';document.getElementById('nameofyourpasswordfield').value='"+pwd+"';");
}

});

Community
  • 1
  • 1
Selali Adobor
  • 2,060
  • 18
  • 30