Skip to content
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

Android 13 issue #303

Closed
bankiprudhvi opened this issue Mar 21, 2023 · 64 comments
Closed

Android 13 issue #303

bankiprudhvi opened this issue Mar 21, 2023 · 64 comments
Labels

Comments

@bankiprudhvi
Copy link

bankiprudhvi commented Mar 21, 2023

Wifi connection success but not connected to wifi ...
mobile -Google pixel 6a

@github-actions
Copy link

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Apr 22, 2023
@ravalum
Copy link

ravalum commented Apr 27, 2023

Probably an issue regarding the new permission workflow NEARBY_WIFI_DEVICES for Android 13+
https://developer.android.com/guide/topics/connectivity/wifi-permissions

Is this repo still active ?
Is there some mainteners ?

@github-actions github-actions bot removed the stale label Apr 29, 2023
@bankiprudhvi
Copy link
Author

still facing lot of issues in Android 10,11,12,13 also one plus not working

@aboozaid
Copy link

Just try react-native-tethering and let me know

@kozhinas
Copy link

Просто попробуйте реагировать на родную привязку и дайте мне знать

Unresolved reference: STATUS_NETWORK_SUGGESTIONS_ERROR_RESTRICTED_BY_ADMIN

@midhun-sa
Copy link

Just try react-native-tethering and let me know

Will this library work for ios?

@aboozaid
Copy link

aboozaid commented Jun 6, 2023

Just try react-native-tethering and let me know

Will this library work for ios?

currently only works for Android but I look for a someone for IOS wrapper.

@midhun-sa
Copy link

Just try react-native-tethering and let me know

Will this library work for ios?

currently only works for Android but I look for a someone for IOS wrapper.

I have tried this this package but when i run pod install i am getting this error

ERROR Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes

@aboozaid
Copy link

aboozaid commented Jun 6, 2023

Just try react-native-tethering and let me know

Will this library work for ios?

currently only works for Android but I look for a someone for IOS wrapper.

I have tried this this package but when i run pod install i am getting this error

ERROR Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes

That's expected. it only works for Android now please if you have any other questions you can open an issue in the lib's repo itself thank you.

@github-actions
Copy link

github-actions bot commented Jul 8, 2023

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Jul 8, 2023
@PrudhviBanki
Copy link

PrudhviBanki commented Jul 14, 2023

Still issue not resolved.

Wifi connection success but not connected to wifi ...
mobile -Google pixel 6a,One plus devices

@github-actions github-actions bot removed the stale label Jul 15, 2023
@PrudhviBanki
Copy link

is this repo people is in active mode ?

@aboozaid
Copy link

aboozaid commented Aug 8, 2023

is this repo people is in active mode ?

Check out my lib react-native-tethering

@MagnasiePro
Copy link
Collaborator

MagnasiePro commented Aug 9, 2023

Experiencing the same error on my device (Google Pixel 6a) as well. I've also raised an issue on react-native-tethering addressing this identical problem. You can find it here: react-native-tethering Issue #23.

@jayadelson
Copy link

I'm seeing the exact issue as well.

@jayadelson
Copy link

In my case, our code drops the existing SSID and connects to a new one for passing FWIW: I have tried adding all the permissions per other comments, including NEARBY_WIFI_DEVICES, and also cleartextTrafficPermitted in the network_security_config.xml file. I've confirmed that no matter how I structure the outbound package with network or axios, it just doesn't send the http text with Android 13. No packets are ever sent or received.

If you manually disconnect the original WiFi, it will send http over the new connection, even though getting the current SSID reports the new one.

@Audrey-Ann
Copy link

Audrey-Ann commented Sep 26, 2023

I am experiencing the same issue on Android 13:

  • If I never connected to that specific Wifi (WifiA)
  • If I call connectToProtectedSSID it successfully passes successfully however the connection is not fulfilled
WifiManager.connectToProtectedSSID(ssid, password, false, false)

FYI: Foreground location permission is granted

@midhungopipk
Copy link

I am experiencing the same issue on Android 13:

  • If I never connected to that specific Wifi (WifiA)
  • If I call connectToProtectedSSID it successfully passes successfully however the connection is not fulfilled
WifiManager.connectToProtectedSSID(ssid, password, false, false)

FYI: Foreground location permission is granted

@Audrey-Ann
Hi even if we connect to wifi from inside our app the connection would only be established temporarily with our application.
you will see a similar message when you go to the Wi-Fi settings screen on Android.

I also faced this issue when I used WifiManager.connectToProtectedSSID(ssid, password, false, false).

@Audrey-Ann
Copy link

@midhungopipk Thank you for your fast reply and explanation!

Do you find a solution or a workaround for it by any chance? :(

@midhungopipk
Copy link

@midhungopipk Thank you for your fast reply and explanation!

Do you find a solution or a workaround for it by any chance? :(

No I just redirected the user to the wifi settings page directly from inside the app.

@Audrey-Ann
Copy link

@midhungopipk I guess there's no better way :(

@JuanSeBestia would you recommend any workaround or explanation on why connecting to the Wi-Fi programatically using connectToProtectedSSID doesn't work with Android 10+? Thanks in advance~

@jayadelson
Copy link

@JuanSeBestia is this library still being maintained?

@YaroslavRoom4
Copy link

Facing the same same with Pixel 7 and Android 14.
Setup: React-Native v72.5 and the latest react-native-wifi-reborn v4.8.3

But it’s strange that what worked with RN v67.5 and RNFR v4.8.3

Is this only related to Pixel Phones?
Has anyone found a solution?

p.s. @JuanSeBestia Tnx for the library!) Works great with other phones!

@jayadelson
Copy link

I have managed to get this working, but it's a little hard to pin down the exact issue.

Besides all the permissions mentioned above, if you're using the forceWifiUsageWithOptions, I found that this should only be called once before you use any connect functions. Near as I can tell, on Android13, every time you call forceWifi, it pops you back to the default network (wlan0). At least in my tests, Android 13 will create a second interface (wlan1) when you connect, then return to wlan0 if you execute the force afterwards.

It's a little confusing...

@JuanSeBestia
Copy link
Owner

Do you know if this MR is solving the issue ?

#319

@dbaonguis-wfc
Copy link

Just try react-native-tethering and let me know

Will this library work for ios?

currently only works for Android but I look for a someone for IOS wrapper.

I have tried this this package but when i run pod install i am getting this error
ERROR Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes

That's expected. it only works for Android now please if you have any other questions you can open an issue in the lib's repo itself thank you.

Hi, how can I avoid this error when I am testing/developing/runing in IOS ?

Copy link

github-actions bot commented Jan 8, 2024

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Jan 8, 2024
@jayadelson
Copy link

I would say that the library just needs some clarification in the docs over the process I described here:

#303 (comment)

I'm not the guy to document this as I don't have enough understanding of the underlying reasons why it works.

@github-actions github-actions bot removed the stale label Jan 15, 2024
@aj-spanio
Copy link

Just chiming in..... I got it to work on Android 14 by doing:
await WifiManager.forceWifiUsageWithOptions(true, { noInternet: true })
await WifiManager.disconnect();
5 second timeout
WifiManager.connectToProtectedSSID
then crucially removing my forceWifiUsageWithOptions that I had been sending AFTER connection.

Hope it helps someone.

Copy link

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Mar 15, 2024
@toni1703
Copy link

Not fixed

@Abdel-Kader
Copy link

Any updates please ? It doesn’t work ! I'm connected but not access to internet on Samsung S21 Android 14

@notjulian
Copy link

Hi folks,
I had the same problem and tried to fix, using the WiFi module of flutter

someone would like to try?

you can add in package.json

"react-native-wifi-reborn": "git+https://github.com/notjulian/react-native-wifi-reborn.git",

or create a patch using patch-package

Code example (for a hotspot without Internet), first connect, then forceWifiUsage true, before disconnect forceWiFiUsage to false

//To connect
await WifiManager.connectToProtectedWifiSSID({
                  ssid: WifiNetToUse,
                  password: pwdWifi,
                  isWEP: false,
                  isHidden: false,
                  timeout: 15,
                })
                  .then(async () => {
                    if (!isIOS)
                      await WifiManager.forceWifiUsageWithOptions(true, {
                        noInternet: true,
                      })
                  })
                  .catch(e => {
                    console.log(e.message, e.code)
                    error = e.code
                  })

//To disconnect
 await WifiManager.forceWifiUsageWithOptions(false, {
            noInternet: false,
})
await WifiManager.isRemoveWifiNetwork(currentSSID)

Copy link

github-actions bot commented May 8, 2024

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label May 8, 2024
@Sotatek-HuyNguyen12
Copy link

I'm still facing this issue on Samsung S23 - Android 14 and Samsung A23 - Android 13.
Does anyone have a solution?

@notjulian
Copy link

I'm still facing this issue on Samsung S23 - Android 14 and Samsung A23 - Android 13. Does anyone have a solution?

have you tried this ?

@github-actions github-actions bot removed the stale label May 15, 2024
@smartmedev
Copy link

Hi @jayadelson is noInternet: Boolean the only option you used? And if it's okay for you to share, can you lay out the steps that allowed you to connect to the network? (which method you called first and how you handle the disconnect/connect)
Thanks in advance!

@Audrey-Ann First, I make sure my permissions are spot on with AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission
        android:required="true"
        android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission 
        android:required="true"
        android:name="android.permission.CHANGE_NETWORK_STATE" />
        <uses-permission
           android:required="true"
           android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission
           android:required="true"
           android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"
                     android:usesPermissionFlags="neverForLocation" />

    <application
      android:networkSecurityConfig="@xml/network_security_config"
    </application>

and my network_security_config. Note that I replace A.B.C.D with the IP address of the device I'm connecting to over the new connection, as I intend on sending clear text info to that device:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <!-- Without localhost setting, you won't be able to connect metro with app. -->
    <domain includeSubdomains="true">127.0.0.1</domain>
    <!-- For  a device, [A.B.C.D] is the address of the the device's network interface -->
    <domain includeSubdomains="true">[A.B.C.D]</domain>
  </domain-config>
</network-security-config>

I then go through a series of permissions checks when the app opens or tries to render the component that will be doing the WiFi activity. Since this is Android 13, it requires the NEARBY_WIFI_DEVICES check which hadn't been required previously, along with the other permissions above. Once those permissions have cleared and check back as granted, I grab the current SSID, and perform a WiFi scan for the newDeviceSSID. Then I begin to run through the process of changing the network in this order. Don't use this code verbatim, it's heavily edited, but gives you the general idea:

    if (Platform.OS == 'android') {
      try {
        if (WifiManager.forceWifiUsageWithOptions && Platform.Version >= 28) {
          await WifiManager.forceWifiUsageWithOptions(true, {noInternet: true});
        }
        if (currentWifi.current != newDeviceSSID) {
          try {
            await WifiManager.isRemoveWifiNetwork(currentWifi.current);
              // Wait for the device to disconnect from the current network
            await new Promise(resolve => setTimeout(resolve, 5000));
          } catch(disconnectError) {
            console.log("Error while disconnecting from WiFi:", disconnectError)
          }
        }
        const data = await WifiManager.connectToProtectedSSID(
          newDeviceSSID,
          password,
          false,
          false,
        );
        } catch (error) {
          console.log(`Android failed to connect to ${newDeviceSSID}.`)
          console.log("Error:", error.message);
          }
        }
    } else {
      [iOS]
      }
    }

Essentially, I first execute the forceWifiUsageWithOptions, then disconnect the current wlan0, then connect the new network, in that order. What isn't in this code is my tracking of the connection status. If the function completes I set the noInternet to be false and restore the original connection.

Hi everyone, I've the same problem connecting to an ioT device via Wi-Fi with no internet access.
Everything works great on Android 13 on Samsung A22.
On Pixel 8 and Android 14, I can't really connect.
The callback fo connectToProtectedSSID and connectToProtectedWifiSSID said successfully connected but on wifi settings the phone really don't change wifi, remain connected on my home local network.

I've tried your steps, like these but is still not working, specially nor disconnect() nor isRemoveWifiNetwork(ssid) works. The phone remain connected to my home local wifi.

Anyone can help me?

@notjulian
Copy link

notjulian commented May 28, 2024

have you tried this ?
@smartmedev

I'm currently using in production, also with Android 14

@smartmedev
Copy link

smartmedev commented May 29, 2024

Hi @notjulian
Yes, i've tried all the code snippets suggested in this thread but nothing works.
I'm using Google Pixel 8 with Android 14.
The problem is that the phone never really disconnect from my home local wifi network even if the library said that it has successfully connected to the ioT device Wi-Fi.

If when I try connection to the ioT Wi-Fi I'm not connected to any other local Wi-Fi network, everything works fine.
What I have found trying these, is that on Google Pixel 8 and Android 14, when I use this library to connect to the ioT Wi-Fi device, when the connection is successfully made via the library classes, if I check on the phone settings, the wifi network not appear to be connected and I don't know why.

@notjulian
Copy link

Hi @notjulian Yes, i've tried all the code snippets suggested in this thread but nothing works. I'm using Google Pixel 8 with Android 14. The problem is that the phone never really disconnect from my home local wifi network even if the library said that it has successfully connected to the ioT device Wi-Fi.

If when I try connection to the ioT Wi-Fi I'm not connected to any other local Wi-Fi network, everything works fine. What I have found trying these, is that on Google Pixel 8 and Android 14, when I use this library to connect to the ioT Wi-Fi device, when the connection is successfully made via the library classes, if I check on the phone settings, the wifi network not appear to be connected and I don't know why.

can you please post your package.json please?

@smartmedev
Copy link

Hi @notjulian

{
  "name": "MyApp",
  "version": "0.0.24",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "debug": "open 'rndebugger://set-debugger-loc?host=localhost&port=8081'"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4.6.3",
    "@invertase/react-native-apple-authentication": "^2.3.0",
    "@mapbox/geo-viewport": "^0.5.0",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-community/netinfo": "^11.3.2",
    "@react-native-community/slider": "^4.5.2",
    "@react-navigation/core": "6.4.16",
    "@react-navigation/drawer": "^6.6.15",
    "@react-navigation/native": "^6.1.17",
    "@react-navigation/native-stack": "^6.9.26",
    "@rnmapbox/maps": "^10.1.24",
    "@sayem314/react-native-keep-awake": "^1.2.3",
    "@types/react-native": "^0.73.0",
    "axios": "^1.7.1",
    "deprecated-react-native-prop-types": "^5.0.0",
    "geolib": "^3.3.4",
    "i18next": "^23.11.4",
    "jwt-decode": "^3.1.2",
    "lodash": "^4.17.21",
    "moment": "^2.30.1",
    "prop-types": "^15.8.1",
    "qs": "^6.12.1",
    "react": "18.2.0",
    "react-i18next": "^14.1.1",
    "react-native": "0.74.1",
    "react-native-android-open-settings": "^1.3.0",
    "react-native-bouncy-checkbox": "^4.0.1",
    "react-native-circular-slider": "^1.0.1",
    "react-native-device-info": "^11.1.0",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "^2.16.2",
    "react-native-get-random-values": "^1.11.0",
    "react-native-google-places-autocomplete": "^2.5.6",
    "react-native-google-signin": "^2.1.1",
    "react-native-gradle-plugin": "^0.71.19",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-option-menu": "^1.1.3",
    "react-native-progress": "^5.0.1",
    "react-native-reanimated": "^3.9.0",
    "react-native-safe-area-context": "^4.10.1",
    "react-native-screens": "^3.31.1",
    "react-native-select-dropdown": "^3.4.0",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^15.3.0",
    "react-native-swipe-gestures": "^1.0.5",
    "react-native-switch": "^1.5.1",
    "react-native-tcp-socket": "6.0",
    "react-native-toast-message": "^2.2.0",
    "react-native-version-check": "^3.4.7",
    "react-native-web": "^0.19.11",
    "react-native-webview": "^13.10.2",
    "react-native-wifi-reborn": "^4.12.1",
    "react-redux": "^7.2.9",
    "redux": "^4.2.1",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.4.2",
    "remote-redux-devtools": "^0.5.16",
    "text-decoding": "^1.0.0",
    "uuid": "^9.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.83",
    "@react-native/eslint-config": "0.74.83",
    "@react-native/metro-config": "0.74.83",
    "@react-native/typescript-config": "0.74.83",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "jest": {
    "preset": "react-native"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@3.6.4"
}

@notjulian
Copy link

notjulian commented May 29, 2024

hi @smartmedev,
if you'd like to try this this
you should change react-native-wifi-reborn in package.json

"react-native-wifi-reborn": "git+https://github.com/notjulian/react-native-wifi-reborn.git",

@smartmedev
Copy link

hi @notjulian thank you, I was missing your import in my package.json.
Anyway I tried to add it and run npm install, but unfortunately nothing changed. I see your changes to the library code, the library said that the connection is successfully done with the ioT device, but data still not pass through that connection.

I'm stucked with this, i think that the only option remain send user to manually connect via the phone settings

@YaroslavRoom4
Copy link

I should note that I only encountered this problem on Pixel phones.
Also I have a suspicion that this may be related to Tensor processors or something related specifically to their phones with that processors.
@smartmedev could you check this?

@smartmedev
Copy link

smartmedev commented May 30, 2024

Hi everyone!
I think I've found a definitive solution. Definitely for my case.
The problem to me was that this library on Google Pixel phone (Android 13/14), returns a feedback that the phone successfully connected to the ioT WiFi but really, from the phone settings, the phone remains connected to my home WiFi network.

The complete scenario of my app is as follows:

  1. I use this library (react-native-wifi-reborn) to connect to the ioT device WiFi directly via app.
  2. When connection is done, i use another library (react-native-tcp-socket) to create a tcp socket connection between app and ioT device via ioT device WiFi.

Based on suggestions made by @jayadelson on this comment. I've debugged Android on native part and I've found that on Pixel phone, if you're already connected to a WiFi with internet access (suppose my home WiFi), when you connect to a WiFi network without internet (ioT device), the phone successfully connect to ioT device WiFi but without disconnecting from home WiFi. So, when you go to the phone WiFi settings, you find that you're connected to your home WiFi and you can see your ioT device WiFi that seems disconnected, ...but you're not!
In reality, on Pixel phones, Android create two concurrent wifi network connection interfaces:
the first is your home WiFi (with internet connection), the second is your ioT with no internet WiFi.

This scenario should be real on every app targeting Android 12 (API 31) or higher (see here: https://developer.android.com/about/versions/12/behavior-changes-12#concurrent-connections)
The fact is that on my Samsung A22 (Android 13), instead, the phone diconnect from home WiFi before connecting to ioT device WiFi and this info reflects on phone WiFi settings.

However, I was focusing that the problems were on this library (react-native-wifi-reborn), but in reality during debug I've found that the two concurrent network interfaces are successfully created.
So I checked the code of react-native-tcp-socket library and I found that it was trying to render all data to the first network interface (wlan0) that is my home WiFi.
So I've made some changes on that library to check all networks that the phone is connected, then
find the desired one based on Dhcp server address or network subnet address, bind all data to desired network and the magic happened!

For everyone who is having a similar problem using these two libraries, I'm posting a PR for the library react-native-tcp-socket.
Here is it the PR for react-native-tcp-socket

Copy link

github-actions bot commented Jul 1, 2024

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Jul 1, 2024
@github-actions github-actions bot closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests