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

@SuppressLint("DefaultLocale")
public static String getAPN(Context context) {
    String apn = "";
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();

    if (info != null) {
        if (ConnectivityManager.TYPE_WIFI == info.getType()) {
            apn = info.getTypeName();/*from w  w w  .j  a  v  a2s  . c om*/
            if (apn == null) {
                apn = "wifi";
            }
        } else {
            apn = info.getExtraInfo().toLowerCase();
            if (apn == null) {
                apn = "mobile";
            }
        }
    }
    return apn;
}

From source file:Main.java

public static boolean IsWifiConnection(Context context) {
    ConnectivityManager conectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return false;
    }/*from   w  w w .  j a  va2  s.c  o m*/
    return networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static int getConnectedType(Context context) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
        return mNetworkInfo.getType();
    }//  ww w  .  j  a  va2  s.  c o m
    return -1;
}

From source file:Main.java

public static boolean isChargeFreeNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo();
    return (activeNetworkInfo != null && activeNetworkInfo.isConnected()
            && (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX
                    || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET));
}

From source file:Main.java

public static int isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return 0;
    } else {//from  w  w  w .  j a v  a  2s  . c o m
        NetworkInfo[] infos = connectivity.getAllNetworkInfo();
        if (infos != null) {
            for (NetworkInfo info : infos) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                        return 1;
                    } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                        String extraInfo = info.getExtraInfo();
                        if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo))
                            return 2;
                        return 3;
                    }
                }
            }
        }
    }
    return 0;
}

From source file:Main.java

public static int isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (NetworkInfo anInfo : info) {
                if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                    if (anInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                        return 1;
                    } else if (anInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                        String extraInfo = anInfo.getExtraInfo();
                        if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo)) {
                            return 2;
                        }/*from ww  w  . ja  v  a 2 s. c  o m*/
                        return 3;
                    }
                }
            }
        }
    }
    return 0;
}

From source file:Main.java

private static boolean isCMWap(Context context) {
    boolean res = false;
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo == null) {
        return res;
    }//ww  w.  j  a  v  a 2 s.  co m
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        if (networkInfo.getExtraInfo().toLowerCase().equals("cmwap")) {
            res = true;
        }
    }

    return res;
}

From source file:Main.java

public static int getConnectedType(Context context) {
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
            return networkInfo.getType();
        }//from w w w  . j  a  v a  2  s  . c  o  m
    }
    return -1;
}

From source file:Main.java

@SuppressLint("DefaultLocale")
public static boolean isCMWap(Context context) {
    boolean res = false;
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo == null) {
        return res;
    }/*from   w  w  w  .j  a v  a  2 s . co  m*/
    int nType = networkInfo.getType();
    String eInfo = networkInfo.getExtraInfo();
    if (nType == ConnectivityManager.TYPE_MOBILE && eInfo != null) {
        if (eInfo.toLowerCase().equals("cmwap")) {
            res = true;
        }
    }

    return res;
}

From source file:Main.java

public static boolean isWifiConnectionAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null) {
        return activeNetworkInfo.isConnected() && activeNetworkInfo.getType() == connectivityManager.TYPE_WIFI;
    } else {//  w w  w. jav a  2  s. c o m
        return false;
    }
}