Unable to call WifiManager.connectToProtectedSSID() on multiple Android API levels
See original GitHub issueTried on:
- Xiaomi A2 Lite - Android 10 (physical device)
- Pixel 2XL - Android 8.1 (emulator)
- Nexus 5X - Android 9 (emulator)
Package versions:
"react": "16.8.6",
"react-native": "0.60.3",
"react-native-wifi-reborn": "^4.1.0"
In my app, I use PermissionsAndroid
to request location permission from the user and a simple form requesting the SSID and password. The “connect” button does something like this:
const connect = () => {
WifiManager.connectToProtectedSSID(this.state.wifiSSID, this.state.password, false)
.then(() => {
// do stuff
})
.catch(() => {
// handle error
});
};
As soon as JS calls WifiManager.connectedToProtectedSSID()
, it crashes with various Malformed calls from JS
errors. I provide the most common one below.
ADB Logcat:
E | ReactNativeJS ▶︎ Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.
│
│ [[6,23,23,23,0,38],[22,1,14,12,9,0],[[475,"RCTView",{"backgroundColor":-10130}],[22,475],[5],[6,6,{"iterations":1,"toValue":1,"frames":[0,0.008888888888888889,0.035555555555555556,0.08000000000000002,0.14222222222222222,0.22222222222222227,0.3200000000000001,0.4355555555555557,0.5644444444444444,0.6799999999999999,0.7777777777777777,0.8577777777777778,0.9199999999999999,0.9644444444444443,0.991111111111111,1,1],"type":"frames"},3547],[128,2000,1590652666206,false]],1770]
│
│ This error is located at:
│ in ConnectWifi (at WithPermissions.js:66)
│ in _temp (created by inject-with-store(_temp))
│ in inject-with-store(_temp) (created by SceneView)
│ in SceneView (created by Drawer)
│ in RCTView (at View.js:35)
│ in View (created by ResourceSavingScene)
│ in RCTView (at View.js:35)
│ in View (created by ResourceSavingScene)
│ in ResourceSavingScene (created by Drawer)
│ in RCTView (at View.js:35)
│ in View (at screens.native.js:132)
│ in ScreenContainer (created by Drawer)
│ in RCTView (at View.js:35)
│ in View (at createAnimatedComponent.js:233)
│ in AnimatedComponent(View) (created by Drawer)
│ in RCTView (at View.js:35)
│ in View (at createAnimatedComponent.js:233)
│ in AnimatedComponent(View) (created by PanGestureHandler)
│ in PanGestureHandler (created by Drawer)
│ in Drawer (created by DrawerView)
│ in DrawerView (created by Navigator)
│ in Navigator (created by SceneView)
│ in SceneView (created by SwitchView)
│ in SwitchView (created by Navigator)
│ in Navigator (created by NavigationContainer)
│ in NavigationContainer (at App.js:12)
│ in App (at installer-app/index.js:15)
│ in MobXProvider (at installer-app/index.js:14)
│ in TribeInstallerApp (at renderApplication.js:40)
│ in RCTView (at View.js:35)
│ in View (at AppContainer.js:98)
│ in RCTView (at View.js:35)
│ in View (at AppContainer.js:115)
└ in AppContainer (at renderApplication.js:39)
I have been unable to debug the native module on Android Studio, as running ./gradlew build --refresh-dependencies
throws the exception below:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-wifi-reborn:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Errors found:
/path/to/project/node_modules/react-native-wifi-reborn/android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java:299: Error: Missing permissions required by WifiManager.getConfiguredNetworks: android.permission.ACCESS_FINE_LOCATION [MissingPermission]
final List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I tried newer and older react-native
versions, to no avail.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
"Could not invoke WifiManager.connectToProtectedSSID ...
I develop an IoT app written in react native and using react-native-wifi-reborn for connecting Wi-Fi, and the app could not connect Wi-Fi ...
Read more >react-native-wifi-reborn - npm
A react-native implementation for viewing and connecting to Wifi networks on Android and iOS devices.. Latest version: 4.7.0, ...
Read more >WifiManager - Android Developers
Provides the results of a call to WifiManager. ... This constant was deprecated in API level 28. This is no longer supported.
Read more >Turn on Wifi and connect to a protected SSID on ios with react ...
import WifiManager from "react-native-wifi-reborn"; ConnectToNetwork = async () => { WifiManager.connectToProtectedSSID("YourSSIDName", "YourPassword" ...
Read more >WifiManager Class (Android.Net.Wifi) | Microsoft Learn
Xamarin.Android has several Android API level settings that determine your app's compatibility with multiple versions of Android. This guide explains what these ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s actually mentioned in the updated readme: https://github.com/JuanSeBestia/react-native-wifi-reborn#isenabled-promiseboolean and also in the release page: https://github.com/JuanSeBestia/react-native-wifi-reborn/releases
I missed it, cause the first release I was notified about was 4.0.1 and did not check earlier release notes… -_-
Kudos mate.