Skip to content

Commit a153240

Browse files
mikehardymatt-oakes
authored andcommitted
fix(android): Handle invalid networks in network listener (#286)
1 parent 716f7f7 commit a153240

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

android/src/main/java/com/reactnativecommunity/netinfo/NetworkCallbackConnectivityReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ void updateAndSend() {
7878
}
7979

8080
if (mNetwork != null) {
81+
// This may return null per API docs, and is deprecated, but for older APIs (< VERSION_CODES.P)
82+
// we need it to test for suspended internet
8183
networkInfo = getConnectivityManager().getNetworkInfo(mNetwork);
8284
}
8385

8486
// Check to see if the network is temporarily unavailable or if airplane mode is toggled on
8587
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
8688
isInternetSuspended = !mNetworkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
8789
} else {
88-
if (mNetwork != null) {
90+
if (mNetwork != null && networkInfo != null) {
8991
NetworkInfo.DetailedState detailedConnectionState = networkInfo.getDetailedState();
9092
if (!detailedConnectionState.equals(NetworkInfo.DetailedState.CONNECTED)) {
9193
isInternetSuspended = true;

0 commit comments

Comments
 (0)