devstepbcn / react-native-android-wifi

A react-native module for viewing and connecting to Wifi networks on Android devices.
ISC License
212 stars 121 forks source link

wifi.findAndConnect(ssid,password) not working in android version 8+ #106

Open nikhilsmg opened 4 years ago

nikhilsmg commented 4 years ago

In android version <8 works fine. but in the latest versions 9, 10. it's not working. Any solution?

digimatt22 commented 4 years ago

@nikhilsmg I don't know if you found an answer to your issue but I am using the library on android version greater than 8. I would guess that you need to enabled course location (or fine location) permission as I believe this requirement was added around version 8 and could be the reason you are unable to successfully connect.

verybluebot commented 3 years ago

A bit off topic, but API level 29 and above (android 10+) has deprecated a lot of the connection method used here. Any upcoming pull requests to fix that? https://developer.android.com/about/versions/10/privacy/changes#configure-wifi

the problematic code is in connectTo() method from what I have noticed:

// If network not already in configured networks add new network
if ( updateNetwork == -1 ) {
        updateNetwork = wifi.addNetwork(conf);
        wifi.saveConfiguration();
}

// if network not added return false
    // TODO: addNetwork() will always return -1 in API 29 and above
if ( updateNetwork == -1 ) {
    return false;
}

   // disconnect current network
    // TODO: disconnect() will always return false in API 29 and above

    boolean disconnect = wifi.disconnect();
if ( !disconnect ) {
    return false;
}

   // enable new network
    // TODO: enableNetwork() will always return false in API 29 and above
    boolean enableNetwork = wifi.enableNetwork(updateNetwork, true);
if ( !enableNetwork ) {
    return false;
}
chilidoggca commented 3 years ago

@nikhilsmg I don't know if you found an answer to your issue but I am using the library on android version greater than 8. I would guess that you need to enabled course location (or fine location) permission as I believe this requirement was added around version 8 and could be the reason you are unable to successfully connect.

For us, the feature broke on android 10+ phones after upgrading our app target sdk version from API Level 28 to 29, in compliance with Play Store. It still works on older android OS phones. We have always requested ACCESS_FINE_LOCATION permission, so it is not the issue.

jdoavila commented 3 years ago

Hi, anyone have a solution for this issue? I have the same problem in API 30, found always return false.

monkin77 commented 3 years ago

I'm also facing the same issue. It would be of great help if there was a solution to this