Answers for "android studio check network connection"

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
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 "android studio check network connection"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language