WiFiFlutter
WiFiFlutter copied to clipboard
Is there any working way to force Android to keep WIFI connected when there is no internet?
Android 11, 12 makes it very hard for iOT devices. It is impossible to connect and configure them as Android detects that the connected WIFI does not have internet connection. Flutter socket connect directly goes into catch exception block with timeout exception.
+1 for that. The android device (my case S22 with july update) always refuses to connect even if withinternet=false
I opened issue on Google Android issue tracker - https://issuetracker.google.com/issues/238443303 . You can comment and give stars so maybe it will get attention.
@elmar001 cc @daadu I am also facing the same problem, according to my check the bindProcessToNetwork method is not working on android 12 and above. I also saw a google issue that mentioned this issue https://issuetracker.google.com/issues/249023377
Thanks, yes there is no way to make it work. About 4 months now and they could not give any explanation in the Google Issue Tracker. New Android 12+ APIs de-facto does not work for IoT connections due to this issue.
The fix in a527cb8dd37fead34c63c4f244b2c929abb1d2d9 should actually work.
@kuhnroyal I know about this PR and I am using plugin version 0.3.18 which already has that new code. But it doesn't seem to work for me. In the issue report google of @elmar001 is also having the same problem, he is also running on the new version. I checked the native code and found that the bindProcessToNetwork method doesn't work, it always fails when running on android 12 and above devices
I have the above problem when running on device: https://www.sony.jp/xperia-sp/products/XQ-BE42/
I dunno about the Xperia, it didn't work on a Pixel 6 for me and I fixed it in a similar way.
I checked the native code and found that the bindProcessToNetwork method doesn't work
This is not happening for me, so you might have another problem.
And how do you check that it doesn't work? On Android 13 this will not change the global Wifi network and will not display in the System-UI. This will be an additional Wifi network that can only be accessed by this app.
@kuhnroyal, Thanks for your help 🙌
Since my app has the function to connect and get data from a camera device, this device will emit a Local Wifi and it has no internet. So, I have to call the method WiFiForIoTPlugin.forceWifiUsage(true) after successfully connecting to the wifi emitted by DashCam to force the phone device to use DashCam wifi (No internet) instead of another network like 5G, because by default, the phone device will give priority to sending app requests via internet connection methods (In case the phone is using 5G and Wifi Iot from DashCam in parallel)
But when I call the WiFiForIoTPlugin.forceWifiUsage(true) method, this method always returns false and the requests I send to DashCam are still sent over 5G even though I have successfully connected to the DashCam's wifi.
So, I cloned the wifi_iot plugin version 0.3.18 and installed it locally in the pubspec*, and check the native code of channel method "forceWifiUsage" and i see it calls bindProcessToNetwork method of ConnectivityManager android class, but when running on Xperia device bindProcessToNetwork method always return false status
https://github.com/flutternetwork/WiFiFlutter/blob/de3a7823b9e9cc479a403641912e90172670ce5d/packages/wifi_iot/android/src/main/java/com/alternadom/wifiiot/WifiIotPlugin.java#L788
I am also connecting to a camera without internet access. But I only have a Pixel 6 to test with so far and it works there.
Try to inspect the joinedNetwork and maybe try to change the code to call selectNetwork directly in connectTo so you can skip the forceWifiUsage call. Other than that I am out of ideas.
@kuhnroyal
Try to inspect the joinedNetwork and maybe try to change the code to call selectNetwork directly in connectTo so you can skip the forceWifiUsage call
I tried it but it still doesn't work, I have attached a picture of the log from the plugin below 😞

@mvn-quannguyen2-dn @elmar001 This problem seems to be the same as mine? https://github.com/flutternetwork/WiFiFlutter/issues/356#issue-1987237191
Yes, it is the exact same issue. More details here: https://issuetracker.google.com/issues/249023377
Sorry wrong link. This one is the one: https://issuetracker.google.com/issues/238443303
@elmar001 Hello, have you encountered this problem? https://github.com/flutternetwork/WiFiFlutter/issues/359