Created
May 28, 2018 13:57
-
-
Save nguyenlinhnttu/0f1623afa624ba0bc88074520771cf69 to your computer and use it in GitHub Desktop.
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 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