Hello, I am trying to connect two android device through wifi. here one device was providing hotspot and another device will connect available wifi. In here am using following code to connect with wifi
mainWifi = (WifiManager)device_list.this. getSystemService(Context.WIFI_SERVICE);
mainWifi.setWifiEnabled(true);
mainWifi.startScan();
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = sr.SSID;
wifiConfig.status = WifiConfiguration.Status.ENABLED;
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfig.priority = 40;
netId = mainWifi.addNetwork(wifiConfig);
mainWifi.disconnect();
mainWifi.enableNetwork(netId, true);
mainWifi.reconnect();
The above code is working perfect in lower version and i had problem with android lollipop. with android lollipop i can not connect with wifi, it fallback with previous one, so i am waiting for perfect solution for this issue. thank you.