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 isMobileConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mMobileNetworkInfo != null) {
            return mMobileNetworkInfo.isConnected() && mMobileNetworkInfo.isAvailable();
        }/*  ww  w.j  a  v a 2 s. com*/
    }
    return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/* www  .j a  va  2  s.co m*/
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (mobile.isConnected() || wifi.isConnected()) {
        return true;
    } else {//from  ww  w . ja v a  2 s  . c  o m
        return false;
    }
}

From source file:Main.java

public static boolean isConnected(Context paramContext) {
    NetworkInfo localNetworkInfo = ((ConnectivityManager) paramContext.getSystemService("connectivity"))
            .getActiveNetworkInfo();//from  w w w. jav a2  s .co m
    return (localNetworkInfo != null) && (localNetworkInfo.isConnected());
}

From source file:Main.java

/**
 * This method is used to check whether GPRS is connected or not.
 * @param appContext//  www.  j a v  a2  s .  c  o  m
 * @return
 */
public static boolean isGPRSConnected(Context appContext) {
    boolean isConnected = false;
    if (isMobileDataEnables(appContext)) {
        ConnectivityManager connMgr = (ConnectivityManager) appContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (mobile != null && mobile.isAvailable() && mobile.isConnected()) {

            isConnected = true;
        }
        return isConnected;
    } else {
        return isConnected;
    }
}

From source file:Main.java

public static int availableCommunication(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean isWifiAvail = ni.isAvailable();
    boolean isWifiConn = ni.isConnected();
    ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    boolean isMobileAvail = ni.isAvailable();
    boolean isMobileConn = ni.isConnected();
    String status = "WiFi\nAvail = " + isWifiAvail + "\nConn = " + isWifiConn + "\nMobile\nAvail = "
            + isMobileAvail + "\nConn = " + isMobileConn + "\n";
    Log.d("Communication State! ", status);
    if (isWifiAvail == true && isWifiConn == true) {
        return ConnectivityManager.TYPE_WIFI;
    } else if (isMobileAvail == true && isMobileConn == true) {
        return ConnectivityManager.TYPE_MOBILE;
    } else {//from ww w .  j a  v  a 2  s  .  co m
        return -1;
    }
}

From source file:Main.java

public static boolean checkNetwork(Context paramContext) {
    NetworkInfo localNetworkInfo = ((ConnectivityManager) paramContext.getSystemService("connectivity"))
            .getActiveNetworkInfo();//  w  ww .j a v a 2 s  .  c om
    if ((localNetworkInfo != null) && (localNetworkInfo.isConnected()))
        ;
    for (boolean bool = true;; bool = false)
        return bool;
}

From source file:Main.java

public static boolean isWifiActive(Context c) { // Check if we are connected to the network via WiFi
    ConnectivityManager connManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifi == null) {
        return false;
    }// w w  w  . j  av  a2  s.  c  o m
    if (wifi.isConnected()) {
        return true;
    }
    return false;
}

From source file:it.unicaradio.android.utils.NetworkUtils.java

public static boolean isConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    for (NetworkInfo info : connectivityManager.getAllNetworkInfo()) {
        if (info.isConnected()) {
            return true;
        }//from  ww  w . ja  v  a2s.co  m
    }

    return false;
}

From source file:Main.java

public static boolean isNetWorkConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            return mNetworkInfo.isAvailable() && mNetworkInfo.isConnected();
        }//from  w w  w.  ja  v a2s. c  o m
    }

    return false;
}