I'm running a small App that scans for available WLAN networks via WifiManager.startScan() / WifiReceiver. As soon as a specific open network is detected I try to connect to it by calling this code:
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.BSSID =result.BSSID; // BSSID of detected network
wifiConfig.priority = 1;
wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConfig.status=WifiConfiguration.Status.ENABLED;
int netId = scanData.wifiManager.addNetwork(wifiConfig);
scanData.wifiManager.enableNetwork(netId, true);
The strange thing here: on my tablet and on some other users smartphones Android crashes! To be clear: it is not my App that fails, the whole device reboots! So what could be the reason for that? Does anybody know a workaround for this problem? Or is there something wrong with my method to connect to a network?
Thanks!
Elmi