Example usage for android.net NetworkInfo isConnected

List of usage examples for android.net NetworkInfo isConnected

Introduction

In this page you can find the example usage for android.net NetworkInfo isConnected.

Prototype

@Deprecated
public boolean isConnected() 

Source Link

Document

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

Usage

From source file:Main.java

public static boolean isNetworkAvailable(Activity activity) {
    ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isMOBILEConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }/*  w w w.  ja v  a 2  s. c o m*/
    return false;
}

From source file:Main.java

/**
 * @return true if there is network connection
 *///from w  w w  . j a  v a  2  s .c  om
static public boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    if (context == null) {
        return false;
    }/*from  ww  w  .  j  a v  a2  s  .  co  m*/
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    return (activeNetInfo != null) && (activeNetInfo.isConnected());
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static synchronized boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();

    if (netInfo != null) {
        return netInfo.isConnected();
    } else {/* w  w  w  .  j a  v  a2 s. c o  m*/
        return false;
    }
}

From source file:Main.java

public static String checkWifiConnection(final Activity activity) throws Exception {
    ConnectivityManager connManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (!mWifi.isConnected()) {
        new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Error")
                .setMessage("Wifi not connected. Application will exit.")
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override/*from  w w w .  j  a  v a2  s . c o m*/
                    public void onClick(DialogInterface dialog, int which) {
                        //activity.finish();
                    }
                }).show();
        throw new Exception("Wifi");
    }
    WifiManager wifiMgr = (WifiManager) activity.getSystemService(Activity.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    return String.format("%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff), (ip >> 24 & 0xff));
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    NetworkInfo net = getConnManager(context).getActiveNetworkInfo();
    return net != null && net.getType() == 1 && net.isConnected();
}

From source file:Main.java

public static int isNetworkAvailable(Activity act) {
    ConnectivityManager connectivityManager = (ConnectivityManager) act
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null && activeNetworkInfo.isConnected())
        return 1;
    else//from w  w  w.  j  a va 2s. c o m
        return 0;
}

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    NetworkInfo net = getConnManager(context).getActiveNetworkInfo();
    return net != null && net.getType() == 0 && net.isConnected();
}