Answers for "how to check network connection android"

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
1

check network connection android

private Boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
Posted by: Guest on August-21-2021

Code answers related to "how to check network connection android"

Browse Popular Code Answers by Language