code: public static boolean isConnected(@NonNull final Context context) {
          final Object service = context.getSystemService(Context.CONNECTIVITY_SERVICE);
          final ConnectivityManager cm = (ConnectivityManager) service;
          final NetworkInfo netInfo = cm.getActiveNetworkInfo();
          return netInfo != null && netInfo.isConnected();
      }
docs: Returns {@code true} if there is an active connection.
  
  @param context The instance of {@link android.content.Context}.
  @return {@code true} if there's an active connection, {@code false} otherwise.
  @throws java.lang.SecurityException If a caller doesn't have the {@link android.Manifest.permission#ACCESS_NETWORK_STATE} permission.