is Network Connected using NetworkInfo - Android android.net

Android examples for android.net:ConnectivityManager

Description

is Network Connected using NetworkInfo

Demo Code

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {

  public static boolean isNetworkConnected(Context context) {
    try {/*from  w w w .jav a 2s.  c o  m*/
      ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo net = conn.getActiveNetworkInfo();
      if (net != null && net.isConnected()) {
        return true;
      }
    } catch (Exception e) {
      return false;
    }
    return false;
  }

}

Related Tutorials