Last active
February 15, 2018 06:40
-
-
Save VarunBarad/f9bde6f004a560b54375d27ad26911c0 to your computer and use it in GitHub Desktop.
Checking network connectivity on Android
This file contains hidden or 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 ConnectivityHelper { | |
public static boolean isConnectedToNetwork(Context context) { | |
ConnectivityManager connectivityManager = | |
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
boolean isConnected = false; | |
if (connectivityManager != null) { | |
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); | |
isConnected = (activeNetwork != null) && (activeNetwork.isConnectedOrConnecting()); | |
} | |
return isConnected; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment