Last active
July 24, 2017 18:14
-
-
Save eufelipe/1794bcd16ea379c9c85854abb4dcbedc 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
/** | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
*/ | |
public static boolean isNetworkAvailable(Context context) { | |
boolean isConnected = false; | |
try { | |
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); | |
isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return isConnected; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment