Git Product home page Git Product logo

Comments (16)

eliaslecomte avatar eliaslecomte commented on July 20, 2024 2

Hey @jkaravakis. Even ACCESS_COARSE_LOCATION should do the trick. There is corrently a bug in the connect logic on line 213 and + of RNWifiModule.java

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { conf.SSID = ssid; } else { conf.SSID = "\"" + ssid + "\""; }

This is not correct. This is fixed in our fork https://github.com/inthepocket/react-native-wifi-reborn and there is a PR open. Waiting for @JuanSeBestia to publish it :-).

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024 2

v2.2.2 seems to have addressed the original issue. Many thanks to @eliaslecomte for the excellent work!

from react-native-wifi-reborn.

eliaslecomte avatar eliaslecomte commented on July 20, 2024 1

The current code requires location permission. It can't scan for wifi networks or connect to one starting Android 6 without it.
I've openen a PR: #13 that makes it possible to connect without the permission but this should indeed be highlighted through the documentation better.

from react-native-wifi-reborn.

JuanSeBestia avatar JuanSeBestia commented on July 20, 2024

What could you see on the console ?, did I get an error?

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024
WifiManager.getCurrentWifiSSID()
      .then(ssid => {
        console.log('Your current connected wifi SSID is ' + ssid);
      })
      .catch(err => {
        console.log('Cannot get current SSID!' + err);
      });

getCurrentWifiSSID logs Your current connected wifi SSID is <unknown ssid>

WifiManager.connectToProtectedSSID('wifiNetwork', 'password', true)
      .then(success => {
        console.log('success' + success);
      })
      .catch(err => {
        console.log(err);
      });

connectToProtectedSSID logs

Error: Can't connect to wifi!
    at Object.fn [as connectToProtectedSSID] (NativeModules.js:99)
    at Welcome.js:20
    at commitHookEffectList (ReactNativeRenderer-dev.js:16921)
    at commitPassiveHookEffects (ReactNativeRenderer-dev.js:16970)
    at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:307)
    at invokeGuardedCallback (ReactNativeRenderer-dev.js:531)
    at flushPassiveEffectsImpl (ReactNativeRenderer-dev.js:20061)
    at unstable_runWithPriority (scheduler.development.js:643)
    at runWithPriority (ReactNativeRenderer-dev.js:5591)
    at flushPassiveEffects (ReactNativeRenderer-dev.js:20031)
WifiManager.loadWifiList(
      function(success) {
        console.log('success!!!');
        console.log(success);
      },
      function(failure) {
        console.log('failure!!!');
      },
    );

loadWifiList logs

success!!!
[]

from react-native-wifi-reborn.

eliaslecomte avatar eliaslecomte commented on July 20, 2024

I am willing to look into making this more clear:

  • update readme
  • return an error telling location permission is required to scan when trying without

@JuanSeBestia can you assign me to this?

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024

Thank you @eliaslecomte! I've implemented a permissions request with PermissionsAndroid for ACCESS_FINE_LOCATION and the loadWifiList and getCurrentWifiSSID functions are now working. However, I still can't get the connectToProtected SSID function to work. I'm getting the following error now:

Error: Can't connect to wifi!
    at Object.fn [as connectToProtectedSSID] (NativeModules.js:99)
    at SetupChecklist.js:45
    at MessageQueue.__invokeCallback (MessageQueue.js:483)
    at MessageQueue.js:135
    at MessageQueue.__guard (MessageQueue.js:384)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:134)
    at debuggerWorker.js:80

I'm going to dig into this a bit more, but any thoughts are much appreciated.

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024

@eliaslecomte you are awesome! I can confirm it works using your fork. Much appreciated!

FYI regarding coarse access, that did not seem to work for me.

from react-native-wifi-reborn.

mferhatkeles avatar mferhatkeles commented on July 20, 2024

I'm having same problems with @jkaravakis and even after defining ACCESS_FINE_LOCATION nothing worked for me.

my logs are same as well,
"Your current connected wifi SSID is "
and
"Error: Can't connect to wifi!"

also I don't know how to get @eliaslecomte 's fork 😞

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024

Hi @mferhatkeles,

I had to use PermissionsAndroid.request to get location permission from the user. Documentation can be founder here: https://facebook.github.io/react-native/docs/permissionsandroid

Essentially you want to run the below function:

PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      );

Hope this helps!

from react-native-wifi-reborn.

mferhatkeles avatar mferhatkeles commented on July 20, 2024

hello @jkaravakis

async function requestAccess() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
//PermissionsAndroid.PERMISSIONS.ACCESS_NETWORK_STATE,
{
'title': 'Wifi networks',
'message': 'We need your permission in order to find wifi networks'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Thank you for your permission! :)");
} else {
console.log("You will not able to retrieve wifi available networks list");
}
} catch (err) {
console.warn(err)
}
}

this is my function to get it and I can get granted every time. but wifi functions do not work. did you totally fix your problem? can you use connectToProtectedSSID ?

from react-native-wifi-reborn.

jkaravakis avatar jkaravakis commented on July 20, 2024

@mferhatkeles I don't see anything wrong with your code, have your tried nesting connecToProtectedSSID within if (granted === PermissionsAndroid.RESULTS.GRANTED)? This structure is working for me.

from react-native-wifi-reborn.

mferhatkeles avatar mferhatkeles commented on July 20, 2024

@jkaravakis ı just tried this and nothing happened 😞

from react-native-wifi-reborn.

eliaslecomte avatar eliaslecomte commented on July 20, 2024

@mferhatkeles there is a problem currently with the connecToProtectedSSID on some Android versions. Can you get the list wifi networks to work?
Did you add the location permission to your android manifest?

from react-native-wifi-reborn.

mferhatkeles avatar mferhatkeles commented on July 20, 2024

@eliaslecomte yes I added the permission to android manifest still does not work. Still I might have problem with permission tho. Where should ı call permission function?

from react-native-wifi-reborn.

JuanSeBestia avatar JuanSeBestia commented on July 20, 2024

v2.2.2 is Released!
But i'm ver taired today to check this issue, sorry :(

from react-native-wifi-reborn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.