fix: registerWifiNetwork for Android 10 and proper result returned#318
fix: registerWifiNetwork for Android 10 and proper result returned#318richirisu wants to merge 14 commits intoflutternetwork:masterfrom
Conversation
…solves flutternetwork/WiFiFlutter flutternetwork#315)
|
@richirisu Currently, your changes ( Let me know what you think about it. |
|
Hello, thanks for your response. I had a look into the (1) Currently, the I don't recommend it, but a minimum fix could be to simply return false in case of Android 10. Something like the following. That reminds me, is there actually a reason that (2) The other issue I see is that the Anyway, I could confirm that a call to the With that information I would suggest the following fix for the Let me know what you think and if I should update my pull request accordingly. |
|
Sorry, for late review!! The changes sounds good to me. The Point 1 - you mentioned, let's just fix that as of now - your current commit does that. |
|
@richirisu as per your suggestion, I have made changes that will return proper |
|
Hey thanks for the efforts of looking into this. Really appreciated. I didn't find any issues regarding the code. I only fixed some minor spelling mistakes. That's all. |
|
Hi all, I tested this branch with android sdk version 33 |
|
I also tested registerWifiNetwork on two differents AP with and without internet |
|
I have been testing this issue on a Pixel phone on Android 13 and I can confirm that the method blocks if awaited for. I looked into it and it is not a Flutter issue. On the Android side However, |
|
Do you know if this is working fine with android 14 ? I do not have pixel telephone to test with android 14 |
|
There might be a bug in the PR. Will fix it in upcoming weeked. |
|
great ! waiting for your fix then. |
|
I have fixed it, please check @aminebagga @richirisu |
|
Now onActivityResult is immediatly called with resultCode Activity.RESULT_CANCELED without waiting for the save network dialog and so registerWifiNetwork always return false |
|
Unfortunately, aminebagga is correct: either way, if I accept the suggested networks or cancel the dialog, the intent's result always defaults to RESULT_CANCELED somehow. That's very strange. I see no wrong-doing in the source code. It matches the official developer guide. https://developer.android.com/develop/connectivity/wifi/wifi-save-network-passpoint-config |
|
@richirisu @daadu if we comment the line "intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);" all will work fine. |
|
Hey, good to know that there is a way to make it work. Personally, I think a return value of true/false is enough, but if you are going for a more specific return value, I would suggest to use an enum on the Flutter side instead of pure integers. I noticed that the Android values use 0 in case of success. Technically, that's OK. Android Flutter enum RegisterWifiNetworkResult{ success, failed, alreadyRegistered }By the way, is iOS unaffected? |
|
Hi @richirisu I did not tested IOS. I'm OK with you for the use of enum |
…sible values. Handle wifi dialog notifications.
Return register operation result as int instead of boolean with 3 pos…
|
Just a short notice but I have merged the suggestions from @aminebagga into this pull request. |
|
If alreadyRegistered is returned but it does not connect to WiFi, how can I connect to a registered device |
You have to open settings, you can use WiFiForIoTPlugin.setEnabled(true, shouldOpenSettings: true), and ask user to click on the registered wifi |
Method registerWifiNetworkDeprecated is not working on Android 10, and instead an exception is raised. The reason is that WifiManager.addNetwork has been deprecated and will always return -1 on Android 10.
Unfortunately, the intent android.provider.Settings.ACTION_WIFI_ADD_NETWORKS is only available from Android 11 onwards. However, by calling WifiManager.addNetworkSuggestions a message will be shown in the system notification area, from where the network can then by added.
Please, have a look at the following Stackoverflow link for more information. There is also a screenshot for how the notification looks like.
https://stackoverflow.com/questions/59753528/creating-a-custom-wifi-setup
Note, that uninstalling the application might cause the network to be removed from the registered networks list.
This solves issue #315