Check internet connection in android

Check internet connection in android using ConnectivityManager to check that you're connected to the internet or not
Check internet connection in android studio 3.5

Check internet connection in android using  ConnectivityManager to check that you're connected to the internet or not.

Follow Below Code:

 protected boolean isOnline() {
        ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

You may like these posts

        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        } else {
            button_retry=(Button)findViewById(R.id.button_retry);
            textView_nointernet=(TextView)findViewById(R.id.textView_noInternet);
            textView_nointernetMessage=(TextView)findViewById(R.id.textView_noInternet_message);
            button_retry.setVisibility(View.VISIBLE);
            textView_nointernet.setVisibility(View.VISIBLE);
            textView_nointernetMessage.setVisibility(View.VISIBLE);
            return false;
        }
    }

    public boolean checkConnection(){
        if(isOnline()){
            return  true;
        }else{
            return  false;
        }

    }

//Here check
if(checkConnection)
{
     //Connected with internet
}
else{
    //Not Connected with internet
}

check internet connection in android

Image Downloaded from: https://www.freepik.com/