WiFiFlutter icon indicating copy to clipboard operation
WiFiFlutter copied to clipboard

WiFi disconnects immediately after findandconnect on Android 11

Open oguzhankosar opened this issue 4 years ago • 11 comments

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.

oguzhankosar avatar Mar 29 '21 18:03 oguzhankosar

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.

daadu avatar Mar 31 '21 11:03 daadu

Also can you share logs for it

daadu avatar Mar 31 '21 11:03 daadu

Also can you confirm that this happens with connect method too?

daadu avatar Mar 31 '21 11:03 daadu

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.

oguzhankosar avatar Apr 02 '21 09:04 oguzhankosar

I can confirm the same, but only when using withInternet: true.

Niek avatar Apr 08 '21 09:04 Niek

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 avatar Apr 08 '21 12:04 daadu

@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.

Niek avatar Apr 08 '21 14:04 Niek

@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 avatar Dec 30 '21 12:12 Deepak-GP

@Deepak-GP findAndConnect requires location permission granted and location service enabled by user.

daadu avatar Dec 31 '21 05:12 daadu

Yeah after providing the location permission it worked. Thank you @daadu

Deepak-GP avatar Jan 03 '22 05:01 Deepak-GP

I suggest that it should be clarified in the documentation of findAndConnect that location permission is needed.

Bennik2000 avatar Oct 03 '23 18:10 Bennik2000