WiFiFlutter
WiFiFlutter copied to clipboard
WiFi disconnects immediately after findandconnect on Android 11
For my IoT app, I'm trying to connect a WiFi programmatically and then make HTTP request. So, I used findAndConnect method. WiFiForIoTPlugin.findAndConnect(ssid, password: password);
Although phone is connected to WiFi successfully, then it disconnects immediately. So HTTP request doesn't work. This problem happens on Android 11. In Android 10 phone, it is working correctly.
This looks like a strange behaviour, I haven't tested on Android 11 device myself. Are you sure that the device you are connecting to is not crashing once phone connects to it.
Also can you share logs for it
Also can you confirm that this happens with connect method too?
Actually I used findAndConnect because connect method didn't work on Android 10. I didn't test it with the other Android versions. Android 11 was not my phone, so I couldn't check it again.
I can confirm the same, but only when using withInternet: true.
withInternet: true uses `NetworkSuggestionAPI.
I would suggest reading - https://developer.android.com/guide/topics/connectivity/wifi-suggest and check with current implementation, if we are missing anything.
My guess is since we are not setting setIsAppInteractionRequired(true) (ad listenting for it in broad cast receiver) while building networkSuggestion, the system is not enforcing it.
@Niek Can you try that as mentioned in the doc and see if that resolves?
@daadu I uncommented the builder.setIsAppInteractionRequired(true); call but this does not fix it - connecting with withInternet: true seems to connect and disconnect immediately. Connecting with withInternet: false works but there's no way to access internet addresses.
@daadu Even I am facing the same issue. Although in my case, it is working fine in Android 11 (Tested with Samsung Galaxy S10E). But it is not working in Android 9 - One plus 3T. And in Android 11, only findAndConnect is working.
In the non working scenario, the findAndConnect method returns false. Is there something extra that needs to be done here?
@Deepak-GP findAndConnect requires location permission granted and location service enabled by user.
Yeah after providing the location permission it worked. Thank you @daadu
I suggest that it should be clarified in the documentation of findAndConnect that location permission is needed.