I need to read a value of 2 edittext being SDDI and Password and connect to that access point with this information
example:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connect2);
cone = (Button) findViewById(conec);
sddi = (EditText) findViewById(R.id.editText);
senha = (EditText) findViewById(R.id.editText2);
cone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (sddi.getText().toString().equalsIgnoreCase("") && senha.getText().toString().equals(" ")) {
Toast.makeText(getApplicationContext(), "Emtre com o Sddi e senha", Toast.LENGTH_LONG).show();
} else {
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// Check for wifi is disabled
if (mainWifi.isWifiEnabled() == false) {
// If wifi disabled then enable it
Toast.makeText(getApplicationContext(), "Wifi desativo, ativando-o",
Toast.LENGTH_LONG).show();
mainWifi.setWifiEnabled(true);
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = String.valueOf(sddi);
wc.preSharedKey = String.valueOf(senha);
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b);
}
}
}
});
}
}