Created
July 13, 2015 18:51
-
-
Save webkader/dac56b234668f0f57bdf to your computer and use it in GitHub Desktop.
Check network is available in 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
/** | |
* isNetworkAvailable() TRUE wenn eine Datenverbindung vorhanden ist | |
* | |
* @param mixed activity | |
* @return | |
*/ | |
public static boolean isNetworkAvailable(Activity activity) { | |
ConnectivityManager connectivity = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (connectivity == null) { | |
return false; | |
} else { | |
NetworkInfo[] info = connectivity.getAllNetworkInfo(); | |
if (info != null) { | |
for (int i = 0; i < info.length; i++) { | |
if (info[i].getState() == NetworkInfo.State.CONNECTED) { | |
return true; | |
} | |
} | |
} | |
} | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment