Skip to content

Instantly share code, notes, and snippets.

@nguyenlinhnttu
Created May 28, 2018 13:57
Show Gist options
  • Save nguyenlinhnttu/0f1623afa624ba0bc88074520771cf69 to your computer and use it in GitHub Desktop.
Save nguyenlinhnttu/0f1623afa624ba0bc88074520771cf69 to your computer and use it in GitHub Desktop.
public class NetWorkUtils {
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivity == null) {
return false;
}
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info == null) {
return false;
}
for (NetworkInfo state : info) {
if (state.getState() == State.CONNECTED) {
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment