Last active
September 5, 2017 08:50
-
-
Save FoxIvan/86aa902901b9cde6c737bc8f4a6dc98f to your computer and use it in GitHub Desktop.
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 NetworkUtil { | |
public static boolean isConnected(Context context) { | |
ConnectivityManager connectManager = | |
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo mobileNetwork = connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | |
NetworkInfo wifiNetwork = connectManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
NetworkInfo activeNetwork = connectManager.getActiveNetworkInfo(); | |
return (activeNetwork != null && activeNetwork.isConnected()) | |
|| mobileNetwork.isConnected() | |
|| wifiNetwork.isConnected(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment