Created
March 13, 2018 12:51
-
-
Save swarawan/bb6a621b924e4bfe521b24e718bb74aa to your computer and use it in GitHub Desktop.
Use this class to check connection availability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NetworkUtils { | |
private static boolean isConnected; | |
public NetworkUtils(Context context) { | |
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (connectivityManager == null) return; | |
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); | |
if (networkInfo == null) return; | |
isConnected = networkInfo.isConnected(); | |
} | |
public boolean isConnected() { | |
return isConnected; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment