Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deanpanayotov/9345441 to your computer and use it in GitHub Desktop.
Save deanpanayotov/9345441 to your computer and use it in GitHub Desktop.
public static boolean isWifiOrMobileActive(Activity activity) {
ConnectivityManager connectivityManager = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
for (NetworkInfo networkInfo : networkInfos) {
if (networkInfo.getTypeName().equalsIgnoreCase("WIFI"))
if (networkInfo.isConnected())
return true;
if (networkInfo.getTypeName().equalsIgnoreCase("MOBILE"))
if (networkInfo.isConnected())
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment