I'm trying to detect internet connectivity on my react-native app.This works perfectly in ios but doesn't work on android.
First I tried importing net-info from react-native. Post this, I tried using the dependency react-native-community/net info "^4.2.2" but it doesn't work.I have tried everything possible like enabling jetifier and also configuring the android settings according to the androidX core but nothing seems to work.
componentDidMount() {
NetInfo.isConnected.addEventListener(
"connectionChange",
this.handleConnectivityChange
);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener(
"connectionChange",
this.handleConnectivityChange
);
}
handleConnectivityChange = isConnected => {
console.log(" OfflineNotice handleConnectivityChange ")
this.props.checkOnlineStatus(isConnected);
this.setState({ isConnected });
};
I expect the netinfo to work in android just like how it does in ios. Am I missing something to include in android. I have already included the required permissions in android. Please help me with this.I've been struggling since a long time.