Following the Android documentation, I'm using this code to connect programmatically to a specific SSID:
private void connectToAP(String ssid, String password) {
...
WifiNetworkSpecifier wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
.setSsid(ssid)
.setWpa2Passphrase(password)
.build();
NetworkRequest.Builder requestBuilder = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(wifiNetworkSpecifier);
NetworkRequest request = requestBuilder.build();
connManager.requestNetwork(request, myNetworkCallback);
...
bindNetwork(); //this method will bind the network without internet
}
as described in the documentation https://developer.android.com/guide/topics/connectivity/wifi-bootstrap#bypass-approval, if I don't forget the network, the second connection to that specific SSID have to bypass the user approval.
My problem is this:
- Call "connectToAP"
- User approval
- Conneted
- After a while the IoT device turns off the wifi for few seconds
- The disconnection callback retries to call the "connectToAP" method (Point 1) but the user approval (Point 2) is not bypassed as expected
What I'm doing wrong? Thank you!