Comments (16)
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.
v2.2.2 seems to have addressed the original issue. Many thanks to @eliaslecomte for the excellent work!
from react-native-wifi-reborn.
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.
What could you see on the console ?, did I get an error?
from react-native-wifi-reborn.
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.
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.
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.
@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.
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.
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.
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.
@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.
@jkaravakis ı just tried this and nothing happened 😞
from react-native-wifi-reborn.
@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.
@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.
v2.2.2 is Released!
But i'm ver taired today to check this issue, sorry :(
from react-native-wifi-reborn.
Related Issues (20)
- Reconnecting to original Wifi HOT 1
- npm ERR! engine Unsupported engine HOT 2
- Can't find a method to connect via BSSID HOT 1
- iot device's http server is not accessible on release build HOT 1
- connectionStatus() is returning 'false' when the Wi-Fi is connected. HOT 2
- Failed to build the app: No package name found. HOT 2
- Multiple commands produce libRNWifi.a HOT 1
- Import only works with path HOT 1
- Android 13 - Not returning correct error when password was wrong HOT 1
- Connection successful even if password provided is wrong? HOT 10
- iOS 17 WifiManager.getCurrentWifiSSID Error HOT 9
- Build error when upgrading to version 4.10.1 (latest). Previously 4.7.0 HOT 3
- CONTRIBUTION: Update EXAMPLE project HOT 3
- Build error after adding this package HOT 2
- Cannot connect to protected SSID on IOS when there's no internet HOT 3
- Error: Cannot detect SSID HOT 2
- v4.12.x produces a runtime error when `connectToProtectedSSID` is called on iOS HOT 6
- Could not determine the dependencies of task ':react-native-wifi-reborn:compileDebugJavaWithJavac'. HOT 2
- Android does not support dual band WIFI frequency bands HOT 1
- react-native-wifi-reborn not working in IOS HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-wifi-reborn.