My app connect directly to a hardware device that act as an access point (with no access to internet).
I can\'t connect because Android 5.0 automat
Just need to correctly format the SSID. Here is a sample code:
WifiManager mWifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
WifiConfiguration tmpConfig = new WifiConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
tmpConfig.SSID = String.format("\"%s\"", sSSID);
tmpConfig.BSSID = sBSSID;
} else {
tmpConfig.SSID = "\"" + sSSID + "\"";
tmpConfig.BSSID = "\"" + sBSSID + "\"";
}
tmpConfig.priority = 1;
if (iSecurityType.equals("WEP")) {
tmpConfig.wepKeys[0] = sPassword;
tmpConfig.wepTxKeyIndex = 0;
} else if (iSecurityType.equals("WPA2") || iSecurityType.equals("WPA")) {
tmpConfig.preSharedKey = "\"" + sPassword+ "\"";
} else {
tmpConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
tmpConfig.status = WifiConfiguration.Status.ENABLED;
int netId = mWifiManager.addNetwork(tmpConfig);
mWifiManager.updateNetwork(tmpConfig);
boolean result = mWifiManager.enableNetwork(netId, true);
mWifiManager.updateNetwork(tmpConfig);
mWifiManager.saveConfiguration();