How to check internet connection before app starts and while it is running?

后端 未结 5 1428
一整个雨季
一整个雨季 2021-01-26 15:59

I found a lot of answer about this but unable to implement those also. I want to implement this code here but not able to do so.

This code I found on google documentatio

5条回答
  •  深忆病人
    2021-01-26 16:12

     protected boolean isNetworkAvilable() {
            boolean isNetworkAvilable = false;
            ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = manager.getActiveNetworkInfo();
            if (info != null && info.isAvailable() && info.isConnected()) {
                isNetworkAvilable = true;
            }
            return isNetworkAvilable;
        }
    
    
       
        
    

提交回复
热议问题