When I do the following first
return await WiFiForIoTPlugin.disconnect() && await WiFiForIoTPlugin.removeWifiNetwork(ssid);
and then call:
final isConnected = await WiFiForIoTPlugin.isConnected();
Why isConnected is still true and then if i make another call, works perfectly fine and returns false, what's the case here I'm using Android version 9.
For example: I'm connected to the current home wifi ssid, then I make call to connectToWiFi function in order to connect to
my Iot device which has wifi endpoint, but on older android versions the first call to await WiFiForIoTPlugin.connect always return false and when i make the second call to this function then everything works.
Thank you :)
Here is the full code:
Future connectToWifi(
ConnectionInfoDto connectionInfoDto, String? deviceWifi) async {
final currentSsid = await WiFiForIoTPlugin.getSSID();
if (Platform.isAndroid) {
final androidInfo = await deviceInfo.androidInfo;
final sdk = androidInfo.version.sdkInt;
if (sdk < 33) {
if (currentSsid != null) {
final disconnected = await disconnectFromWifi(currentSsid);
log("$disconnected disconnected");
}
if (deviceWifi != null) {
await WiFiForIoTPlugin.removeWifiNetwork(deviceWifi);
await WiFiForIoTPlugin.disconnect();
await WiFiForIoTPlugin.forceWifiUsage(false);
}
}
}
final isConnected = await WiFiForIoTPlugin.isConnected();
final response = await WiFiForIoTPlugin.connect(
connectionInfoDto.ssid,
password: connectionInfoDto.password,
security: connectionInfoDto.securityType == SecurityType.secured
? NetworkSecurity.WPA
: NetworkSecurity.NONE,
);
log("$response response");
if (!response) {
throw 'Failed to Connect';
}
if (response) await WiFiForIoTPlugin.forceWifiUsage(true);
When I do the following first return await WiFiForIoTPlugin.disconnect() && await WiFiForIoTPlugin.removeWifiNetwork(ssid); and then call: final isConnected = await WiFiForIoTPlugin.isConnected(); Why isConnected is still true and then if i make another call, works perfectly fine and returns false, what's the case here I'm using Android version 9.
For example: I'm connected to the current home wifi ssid, then I make call to connectToWiFi function in order to connect to my Iot device which has wifi endpoint, but on older android versions the first call to await WiFiForIoTPlugin.connect always return false and when i make the second call to this function then everything works.
Thank you :)
Here is the full code: Future connectToWifi(
ConnectionInfoDto connectionInfoDto, String? deviceWifi) async {
final currentSsid = await WiFiForIoTPlugin.getSSID();
}