Open charle692 opened 6 years ago
We have similar issue for Android 5.1, Micromax q392. Let me try this one.
It does not work, actually i found that as per this link not able to access configured wifi networks. Is it possible that the wifi service is break when we try to call it?
So, it never goes inside the for loop, and so no chance to even get the network ID! :(
@ParthBarot-BoTreeConsulting In my case the wifi list contains the proper wifi networks. So the loop actually executes. I added logging inside the loop to verify that the code was in-fact looping as expected.
The issue that I described above only occurs on Android 6 and higher. So this shouldn't affect Android 5.1. I forgot to add the following link to my first comment. It confirms the issue that I'm describing.
https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network
Actually, this issue happens because of "
in SSID and passphrase given to the conf. As per the docs and some developer references, initially we found that "
is not needed for newer versions of Android after Lollipop. And this is the same code which is done in this library.
So It is like,
IF build >= LOLLIPOP && PHONE != MicroMax Q392 THEN
NO_QUOTES_IN_SSID_AND_PASS
ELSE
QUOTES_IN_SSID_AND_PASS
END
Fixed it by adding quotes in both, works fine. I believe it would be helpful to someone.
Thanks
Starting in Android 6.0 apps can now only change a network configuration if they created it in the first place. https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network
Meaning that if the network was created by another app or the user themselves, findAndConnect will always return false.
The code in question is in connectTo specifically the loop compares current wifi configuration to the new configuration.
wifi.updateNetwork(conf) will always return -1 in the case described above.
To fix it, one can replace
updateNetwork = wifi.updateNetwork(conf);
withupdateNetwork = conf.networkId;
.I can create a pull request if you are interested in this fix. Is there a reason why
wifi.updateNetwork
is used?