Broadcast receiver for checking internet connection in android app

后端 未结 21 3209
温柔的废话
温柔的废话 2020-11-21 22:28

I am developing an android broadcast receiver for checking internet connection.

The problem is that my broadcast receiver is being called two times. I want it to get

21条回答
  •  时光说笑
    2020-11-21 22:49

    It's easier to use https://github.com/JobGetabu/DroidNet

     @Override
        public void onInternetConnectivityChanged(boolean isConnected) {
    
            if (isConnected) {
                //do Stuff with internet
                netIsOn();
            } else {
                //no internet
                netIsOff();
            }
        }
    
        private void netIsOn(){...}
    
        private void netIsOff(){...}
    

提交回复
热议问题