Answers for "how to check internet connection android studio"

1

android studio check network connection

//beware that (contextname) is your activity name like if your working on
//activity with name of FirstActivity then instead of (contextname)
//write **FirstActivity.this**.getSystemService...

ConnectivityManager cm =
        (ConnectivityManager)contextname.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
                      activeNetwork.isConnectedOrConnecting();

//in the end boolean Variable isConnected should hold the Status 
//of your network Connection if isConnected is true then you have active network
//otherwise if its false you have no internet Connection
Posted by: Guest on August-31-2021

Code answers related to "how to check internet connection android studio"

Browse Popular Code Answers by Language