android studio check network connection

Solutions on MaxInterview for android studio check network connection by the best coders in the world

showing results for - "android studio check network connection"
Naomie
27 Sep 2020
1private Boolean isNetworkAvailable() {
2    ConnectivityManager connectivityManager 
3          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
4    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
5    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
6}
Zed
31 Apr 2018
1//beware that (contextname) is your activity name like if your working on
2//activity with name of FirstActivity then instead of (contextname)
3//write **FirstActivity.this**.getSystemService...
4
5ConnectivityManager cm =
6        (ConnectivityManager)contextname.getSystemService(Context.CONNECTIVITY_SERVICE);
7
8NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
9boolean isConnected = activeNetwork != null &&
10                      activeNetwork.isConnectedOrConnecting();
11
12//in the end boolean Variable isConnected should hold the Status 
13//of your network Connection if isConnected is true then you have active network
14//otherwise if its false you have no internet Connection
15