Skip to content

Commit

Permalink
fix(android): use registerDefaultNetworkCallback so toggling airplane…
Browse files Browse the repository at this point in the history
… mode works (#571)
  • Loading branch information
akinyele committed Feb 7, 2022
1 parent a7c7b10 commit e8af2de
Showing 1 changed file with 1 addition and 4 deletions.
Expand Up @@ -13,7 +13,6 @@
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -53,16 +52,14 @@ public NetworkCallbackConnectivityReceiver(ReactApplicationContext reactContext)
@SuppressLint("MissingPermission")
public void register() {
try {
NetworkRequest.Builder builder = new NetworkRequest.Builder();

// Similar to BroadcastReceiver implementation, we need to force
// an initial callback call in order to get the current network state,
// otherwise, an app started without any network connection will
// always be reported as "unknown".
mNetwork = getConnectivityManager().getActiveNetwork();
asyncUpdateAndSend(0);

getConnectivityManager().registerNetworkCallback(builder.build(), mNetworkCallback);
getConnectivityManager().registerDefaultNetworkCallback(mNetworkCallback);
} catch (SecurityException e) {
// TODO: Display a yellow box about this
}
Expand Down

0 comments on commit e8af2de

Please sign in to comment.