code: @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE)
      public static void register(@NonNull Context context, @NonNull ConnectivityListener listener) {
          if (receiversMap.containsKey(listener)) {
              throw new RuntimeException("Connectivity listener " + listener
                      + " is already registered");
          }
  
          final ConnectivityReceiver receiver = new ConnectivityReceiver(listener);
          receiversMap.put(listener, receiver);
          context.registerReceiver(receiver,
                  new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
          receiver.notify(isConnected(context));
      }
docs: Be sure to remove receiver at appropriate time (i.e. in Activity.onPause()).