pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 276 forks source link

isConnectedToInternet always false #463

Closed asknask closed 2 years ago

asknask commented 2 years ago

Describe the bug The value is always false, even if internet is connected. The observer also doesn't get triggered if I change network state by turning off wifi and data.

To Reproduce

InternetObservingSettings settings = InternetObservingSettings.builder()
                .initialInterval(0)
                .interval(5000)
                .strategy(new SocketInternetObservingStrategy())
                .build();

        disposable = ReactiveNetwork
                .observeInternetConnectivity(settings)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(isConnectedToInternet  -> {
                    isInternetConnected = isConnectedToInternet;
                    if(!isInternetConnected)
                    {
                        Toasty.warning(getApplicationContext(), R.string.not_connected_internet).show();
                    }
                });
    }

    @Override
    public void onTerminate()
    {
        super.onTerminate();
        if(disposable != null && !disposable.isDisposed())
        {
            disposable.dispose();
        }
    }

Expected behavior isConnectedToInternet should return true. Observer should be triggered if internet is not connected.

Smartphone (please complete the following information):