Example usage for android.net NetworkInfo getType

List of usage examples for android.net NetworkInfo getType

Introduction

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

Prototype

@Deprecated
public int getType() 

Source Link

Document

Reports the type of network to which the info in this NetworkInfo pertains.

Usage

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean is3gConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
}

From source file:Main.java

public static boolean isWifiConnect(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkINfo = cm.getActiveNetworkInfo();
    if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }//from  www  .j a  va2s  . c om
    return false;
}

From source file:Main.java

public static boolean isConnectedToWifi(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkINfo = cm.getActiveNetworkInfo();
    if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }//w w  w  .java2 s .c  o  m
    return false;
}

From source file:Main.java

public static boolean isWIFI(Context context) {
    try {/*from   ww w . ja  v  a 2  s .  c  o m*/
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm != null) {
            NetworkInfo ni = cm.getActiveNetworkInfo();
            if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
                return true;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:Main.java

public static boolean is3G(Context context) {
    try {//  w  w w.  ja  v  a  2s . c o m
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm != null) {
            NetworkInfo ni = cm.getActiveNetworkInfo();
            if (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE) {
                return true;
            }
        }
    } catch (Exception e) {

    }
    return false;
}

From source file:Main.java

public static boolean isOnlineOnMobile(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:Main.java

public static boolean isWifiConnected(ConnectivityManager cm) {
    if (cm != null) {
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }//from w w  w  . ja va2  s. co  m
    }
    return false;
}

From source file:Main.java

/**
 * To check whether current network is wifi.
 *
 * @param context context/*from   w w w .j  a  v a  2s  . c om*/
 * @return true if network if wifi, otherwise return false
 */
protected static boolean isWifi(Context context) {
    if (context == null) {
        return false;
    }

    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();

    return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI);
}