Last active
December 15, 2015 00:58
-
-
Save mertsimsek/5176167 to your computer and use it in GitHub Desktop.
Looks for internet availability on Android.
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
public class InternetAvailability{ | |
public boolean isInternetAvailable(){ | |
try { | |
ConnectivityManager nInfo = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
nInfo.getActiveNetworkInfo().isConnectedOrConnecting(); | |
Log.i(TAG, "Net avail:" | |
+ nInfo.getActiveNetworkInfo().isConnectedOrConnecting()); | |
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo netInfo = cm.getActiveNetworkInfo(); | |
if (netInfo != null && netInfo.isConnectedOrConnecting()) { | |
Log.i(TAG, "Network is available"); | |
return true; | |
} else { | |
Log.i(TAG, "Network is not available"); | |
return false; | |
} | |
} catch (Exception e) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment