Skip to content

Instantly share code, notes, and snippets.

@FoxIvan
Last active September 5, 2017 08:50
Show Gist options
  • Save FoxIvan/86aa902901b9cde6c737bc8f4a6dc98f to your computer and use it in GitHub Desktop.
Save FoxIvan/86aa902901b9cde6c737bc8f4a6dc98f to your computer and use it in GitHub Desktop.
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