Example usage for android.net NetworkInfo getTypeName

List of usage examples for android.net NetworkInfo getTypeName

Introduction

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

Prototype

@Deprecated
public String getTypeName() 

Source Link

Document

Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE".

Usage

From source file:Main.java

public static boolean isNetworkAvailable(ConnectivityManager cm) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    NetworkInfo[] mNetInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : mNetInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }/*  w  w w. j  a v  a 2 s.  co m*/
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean isNetworkAvailable(ConnectivityManager obj) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = obj;//from  w ww .  j  a v a2s  .co  m
    NetworkInfo[] mNetInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : mNetInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean haveNetworkConnection(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }// www .j av  a2s  . co  m
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }/*from   w  w  w . j a  v  a  2 s  .co m*/
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean checkConnection(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }/*from www.  j a  v a 2s  . c  om*/
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

/**
 * Checks whether the device is connected to a network
 *///from ww w . j a v  a  2  s.  com
public static boolean hasInternet(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

/**
 * Metodo para saber si se tiene conexion a internet
 * por medio de datos o wifi// w w  w  . j  a  va 2  s  . co m
 * @param context
 * @return
 */
public static boolean hasInternet(Context a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase(WIFI_TYPE_NAME))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase(MOBILE_TYPE_NAME))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

/**
 * Checks for network connectivity either via wifi or cellular.
 * @param context The context of the activity doing the checking
 * @return A Boolean. True if they have connection, false if they do not
 *//* w  ww.j a  v a  2 s .  c  om*/
public static boolean haveNetworkConnection(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    if (context == null) {
        return false;
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean checkInternetConnection(Context context) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    try {//from ww  w. j  av  a 2 s. c  o  m
        NetworkInfo[] netInfo = cm.getAllNetworkInfo();
        for (NetworkInfo ni : netInfo) {
            if (ni.getTypeName().equalsIgnoreCase("WIFI"))
                if (ni.isConnected())
                    haveConnectedWifi = true;
            if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
                if (ni.isConnected())
                    haveConnectedMobile = true;
        }
    } catch (Exception e) {
        e.getStackTrace();
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:Main.java

public static boolean HaveNetworkConnection(Context ctx) {

    boolean HaveConnectedWifi = false;
    boolean HaveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI")) {
            if (ni.isConnected()) {
                HaveConnectedWifi = true;
            }/*w w  w  . ja  v  a 2  s .c o m*/
        }
        if (ni.getTypeName().equalsIgnoreCase("MOBILE")) {
            if (ni.isConnected()) {
                HaveConnectedMobile = true;
            }
        }
    }
    return HaveConnectedWifi || HaveConnectedMobile;
}