Last active
April 2, 2020 21:38
-
-
Save pkavoo/d2cab3bdf44217699a0d1ed52f4b488a to your computer and use it in GitHub Desktop.
Method for checking if internet is turned on
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 static boolean isInternetConnected(Context ctx) { | |
ConnectivityManager connectivityMgr = (ConnectivityManager) ctx | |
.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo wifi = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | |
// Check if wifi or mobile network is available or not. If any of them is | |
// available or connected then it will return true, otherwise false; | |
if (wifi != null) { | |
if (wifi.isConnected()) { | |
return true; | |
} | |
} | |
if (mobile != null) { | |
if (mobile.isConnected()) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment