I want to connect to a wifi network so I try this:
WifiConfiguration wfc = new WifiConfiguration();
wfc.SSID = "\"".concat( sid ).concat("\"");
wfc.preSharedKey = "\"".concat( pwd ).concat("\"");
WifiManager wfMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
int networkId = wfMgr.addNetwork(wfc);
if (networkId != -1) {
// success, can call wfMgr.enableNetwork(networkId, true) to connect
} else {
// fails
}
but networkId is always -1 where is the error?
The necessary permissions are also added in the manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" android:required="true"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" android:required="true"/>