react-native-community / react-native-netinfo listners are not working on android

1.3k Views Asked by At

 state = {
    isConnected: null,
  };
  
    componentDidMount() {
    this._netWorkConnection();
  }
  
  componentWillUnmount() {
    this._netWorkConnection();
  }
  
    _netWorkConnection = () => {
    NetInfo.addEventListener(state => {
      console.log('Is connected?', state.isInternetReachable);

      const connection = state.isInternetReachable;

      this.setState(
        {
          isConnected: connection,
        },
        () => {
          if (this.state.isConnected === false) {
            this._showConnectionMessage();
          }
        },
      );
    });
  };

_showConnectionMessage() {
  Util.showMessage('No internet');
}
  
  

react-native-community / react-native-netinfo listners are not working on android but it is working fine in iOS though i have added internet permissions in my android manifest <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> and has added androidXCore = "1.0.2" in build.gradle but no luck in android , below is my code

1

There are 1 best solutions below

0
On

this code is fine it is just not working in simulator while it is working fine on any other physical device