With Android 10, I'm using the following method to connect to my Wifi Access Point :
@RequiresApi(api = Build.VERSION_CODES.Q)
public static void connectToWifiAccessPoint(String AP_SSID, String AP_PASSWORD, ConnectivityManager connectivityManager) {
WifiNetworkSpecifier.Builder builder = null;
builder = new WifiNetworkSpecifier.Builder();
builder.setSsid(AP_SSID);
builder.setWpa2Passphrase(AP_PASSWORD);
WifiNetworkSpecifier wifiNetworkSpecifier = builder.build();
NetworkRequest.Builder networkRequestBuilder = new NetworkRequest.Builder();
networkRequestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
networkRequestBuilder.setNetworkSpecifier(wifiNetworkSpecifier);
NetworkRequest networkRequest = networkRequestBuilder.build();
connectivityManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(@NonNull Network network) {
super.onAvailable(network);
connectivityManager.bindProcessToNetwork(network);
}
});
}
A few seconds after calling this method, the OS displays this pop-up:
After hitting the connect button, the same pop-up appears a few seconds later, and the smartphone is still not connected to the access point.
Any idea how to fix this please ?