In React Native Android How to check internet connection is online /offline in application background?
19,962
Solution 1
import { NetInfo } from 'react-native';
NetInfo.isConnected.fetch().then(isConnected => {
if(isConnected)
{
console.log('Internet is connected');
}
})
This above code is sufficient to check if there is active net connection or not
Solution 2
NetInfo API is used for checking internet connection.
eg: NetInfo.isConnected.addEventListener('change', this._handleConnectionChange);
refer https://facebook.github.io/react-native/docs/netinfo.html for more details.
Related videos on Youtube
Author by
Saravana Kumar
Updated on September 15, 2022Comments
-
Saravana Kumar over 1 year
I need to check Internet Connection while Application Background
-
Saravana Kumar about 7 yearsIs it NetInfo can check internet connection in application background also ? @JainZz
-
Saravana Kumar about 7 yearsI would check that code , but it can run only on application running time, that can't work in application background. @JainZz
-
Cobolt about 7 yearsIf you want it to work in the background you'll have to implement your code in java/objective-c natively
-
Rushi trivedi almost 6 yearsnot working in iOS
-
Nabeel K over 5 yearsthis gives 'connected' response if my internet is down but connected to wifi. How can I detect that case ?
-
hzak over 4 yearsNetInfo is deprecated. This plugin needs to be used instead github.com/react-native-community/react-native-netinfo