-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wifi.findAndConnect not connecting to wifi if Mobile data is switched on OS 9 #76
Comments
I fixed it. |
Can you tell me how you fixed it? |
Can you tell me how you fixed it? i am facing same issue |
I have resolved the issue, now it is working fine for me we need to make the changes in AndroidWifiModule class. Try to replace the code with below code. package com.devstepbcn.wifi; import com.facebook.react.uimanager.; import org.json.JSONArray; public class AndroidWifiModule extends ReactContextBaseJavaModule { //WifiManager Instance //Constructor wifi = (WifiManager)reactContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE); //Name for module register to use: //Method to load wifi list into string via Callback. Returns a stringified JSONArray for (ScanResult result: results) { //Method to force wifi usage if the user needs to send requests via wifi //Receives a boolean to enable forceWifiUsage if true, and disable if false.
//builder.addCapability(NetworkCapabilities.TRANSPORT_WIFI); //Use this method to make sure that your forced network already bound //Method to check if wifi is enabled //Method to connect/disconnect wifi service //Send the ssid and password of a Wifi network into this to connect to the network. //Use this method to check if the device is currently connected to Wifi. //Method to connect to WIFI Network
conf.allowedAuthAlgorithms.clear();
conf.SSID = String.format(""%s"", ssid); String capabilities = result.capabilities; conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN); } else if (capabilities.contains("WEP")) { List mWifiConfigList = wifi.getConfiguredNetworks(); int updateNetwork = -1; // Use the existing network config if exists // If network not already in configured networks add new network
if ( updateNetwork == -1 ) {
boolean disconnect = wifi.disconnect(); // enable new network return true; conf.SSID = """ + ssid + """; //Add a hidden wifi network and connect to it int updateNetwork = -1; // check if network config exists and it's hidden // If network not already in configured networks add new network // if network not added return false // enable new network wifi.saveConfiguration(); networkAdded.invoke(true); //Disconnect current Wifi. //This method will return current ssid // This value should be wrapped in double quotes, so we need to unwrap it. callback.invoke(ssid); //This method will return the basic service set identifier (BSSID) of the current access point String bssid = info.getBSSID(); callback.invoke(bssid.toUpperCase()); //This method will return current wifi signal strength //This method will return current wifi frequency //This method will return current IP //This method will remove the wifi network as per the passed SSID from the device list for (WifiConfiguration wifiConfig : mWifiConfigList) { @ReactMethod @ReactMethod public static String longToIP(int longIp){ private WifiConfiguration IsExist(String SSID) { for (WifiConfiguration existingConfig : existingConfigs) { class WifiReceiver extends BroadcastReceiver { private Callback successCallback; public WifiReceiver(final WifiManager wifi, Callback successCallback, Callback errorCallback) { // This method call when number of wifi connections changed try { for (ScanResult result: results) { |
@Pankajmalhan could you please explain the change that you made or paste it again within a code block? It seems like Github formatting stripped some of the code. Thanks! |
Hi @gpawlik following is the list of changes that I made.
Change 2: Replace Force Wifi Usage with below code
Change 3: Replace code of connectionStatusOfBoundNetwork method with the following code These are the changes that you need to make and this is code how I am connecting to devices.
I need to implement setTimeout here because forceWifiUsage some time to make a force connections. |
I don't why this code is formatting, you can download file from here AndoirdWifiModule.java
|
@Pankajmalhan given code doesn't work for do we need to make any other changes in AndroidManifest.xml or another file? |
@preetlotey999 can you please help on this? I am also having the same scenario, could you please post your fix? |
I'm also having issues with Android 9. |
I am trying to connect with IOT device its working in some devices but not working specifically in OS 9 and some OS 8 versions. Please assist.
Thanks
The text was updated successfully, but these errors were encountered: