Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created January 1, 2014 12:03
Show Gist options
  • Save ishitcno1/8207397 to your computer and use it in GitHub Desktop.
Save ishitcno1/8207397 to your computer and use it in GitHub Desktop.
Android methods to check the network connection.
public static boolean isWifiConn(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return networkInfo.isConnected();
}
public static boolean isMobileConn(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
return networkInfo.isConnected();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment