You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
findAndConnect should only return true upon connection success #4
The comment and console logs you have here says it will return true if its in range, since the function is findAndConnect shouldn't this only return true once it actually connects? Otherwise whats the best way to know that its been connected?
//found returns true if ssid is in the rangewifi.findAndConnect(ssid,password,(found)=>{if(found){console.log("wifi is in range");}else{console.log("wifi is not in range");}});
Android doesn’t provide a callback when you try to connect to a wifi network. You have to listen for connectivity changes to know if connection succeeded. You can use NetInfo from React Native Components to do it. If findAndConnect function returns false, you don't need to listen for this connectivity changes so you are not in range.
Yes, sure! It would be nice to have some help to improve it. The lib could handle all this logic and provide the desired callback. I leave this issue open, thanks!
My application needs to know the wifi password for another purpose. Let's say the user has the password already configured for this specific SSID.
I do the following:
-Request password
-Disconnect the user from the network
-Call findAndConnect()
If the user has input the correct password then it will connect and netinfo will generate an event.
However, if the user has input an incorrect password then it will not connect, but the Android wifi daemon might take over and connect the phone to the SSID with the correct stored password, and thus netinfo will generate the same event.
This means there is no way to know if the password is correct or not.
Is there a way to stop the wifi daemon from connecting automatically? Is there a way to delete the network configuration for that SSID?
There's a few methods that could be used for this, if you take a look at the fork of WifiWizard I have, you will see one PR I merged from original repo that checks in a for loop before resolving promise:
@asCii88 That is the exact conclusion I've arrived to and this is completely stupid. Have you managed to find a way around it by any means? I've tried every combination of findAndConnect/netinfo/remove networks.. but with no luck.
so I am trying to loop until the SSID is visible (think of it as a hardware device that has its own Hotspot). What would be the proper process to continue to try to connect to it?
Activity
devstepbcn commentedon Oct 24, 2016
Hi corymsmith,
Android doesn’t provide a callback when you try to connect to a wifi network. You have to listen for connectivity changes to know if connection succeeded. You can use NetInfo from React Native Components to do it. If findAndConnect function returns false, you don't need to listen for this connectivity changes so you are not in range.
corymsmith commentedon Oct 24, 2016
I'm familiar with NetInfo, I guess it would be nice of this lib handled some of that but I completely understand why it currently doesn't :)
corymsmith commentedon Oct 24, 2016
If I have time maybe I'll submit a PR, otherwise we can probably close this.
devstepbcn commentedon Oct 25, 2016
Yes, sure! It would be nice to have some help to improve it. The lib could handle all this logic and provide the desired callback. I leave this issue open, thanks!
scriptfans commentedon Jan 3, 2017
+1 for this
asCii88 commentedon Jun 30, 2017
My application needs to know the wifi password for another purpose. Let's say the user has the password already configured for this specific SSID.
I do the following:
-Request password
-Disconnect the user from the network
-Call findAndConnect()
If the user has input the correct password then it will connect and netinfo will generate an event.
However, if the user has input an incorrect password then it will not connect, but the Android wifi daemon might take over and connect the phone to the SSID with the correct stored password, and thus netinfo will generate the same event.
This means there is no way to know if the password is correct or not.
Is there a way to stop the wifi daemon from connecting automatically? Is there a way to delete the network configuration for that SSID?
Edit: I've seen now that the code is supposed to delete that network
https://github.com/devstepbcn/react-native-android-wifi/blob/master/android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java#L142
This doesn't work, because, according to the documentation
This happens from Android 6.0 onwards
skibz commentedon Oct 10, 2017
based on this - it looks like one could emit an event or fulfill a promise (or both) when this broadcast receiver is invoked.
tripflex commentedon Feb 21, 2018
There's a few methods that could be used for this, if you take a look at the fork of WifiWizard I have, you will see one PR I merged from original repo that checks in a for loop before resolving promise:
https://github.com/tripflex/WifiWizard2/blob/master/src/android/wifiwizard2/WifiWizard2.java#L532-L561
iuliuvisovan commentedon Jul 9, 2018
@asCii88 That is the exact conclusion I've arrived to and this is completely stupid. Have you managed to find a way around it by any means? I've tried every combination of findAndConnect/netinfo/remove networks.. but with no luck.
jnystrom commentedon Feb 1, 2019
so I am trying to loop until the SSID is visible (think of it as a hardware device that has its own Hotspot). What would be the proper process to continue to try to connect to it?