Example usage for android.net NetworkInfo getExtraInfo

List of usage examples for android.net NetworkInfo getExtraInfo

Introduction

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

Prototype

@Deprecated
public String getExtraInfo() 

Source Link

Document

Report the extra information about the network state, if any was provided by the lower networking layers.

Usage

From source file:Main.java

public static int getMobileService(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info2 = conn.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (info2 == null || info2.getExtraInfo() == null) {
        return MOBILE_SERVICE_UNKNOW;
    }//from  ww  w.j av  a  2 s.co  m
    String info = info2.getExtraInfo().toLowerCase();
    // //3gnet/3gwap/uninet/uniwap/cmnet/cmwap/ctnet/ctwap
    if ("3gwap".equals(info) || "3gnet".equals(info) || "uninet".equals(info) || "uniwap".equals(info)
            || "3gwap".equals(info)) {
        return MOBILE_SERVICE_UN;
    } else if ("cmnet".equals(info) || "cmwap".equals(info)) {
        return MOBILE_SERVICE_CM;
    } else if ("ctnet".equals(info) || "ctwap".equals(info)) {
        return MOBILE_SERVICE_CT;
    } else {
        return MOBILE_SERVICE_UNKNOW;
    }
}

From source file:Main.java

public static String getExtraInfo(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
    if (nwInfo == null) {
        return null;
    }/*w w  w . ja va2 s  .co m*/
    String extraInfo = nwInfo.getExtraInfo();
    String typeName = nwInfo.getTypeName();
    if (typeName != null && typeName.equalsIgnoreCase("WIFI")) {
        return typeName;
    }
    return extraInfo;
}

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  ww .  ja  v  a2  s. c  o  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

@SuppressLint("DefaultLocale")
public static String getAPNTypeString(Context context) {
    String netType = "";
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null) {
        int nType = networkInfo.getType();
        if (nType == ConnectivityManager.TYPE_MOBILE) {
            String eInfo = networkInfo.getExtraInfo();
            if (eInfo != null) {
                netType = eInfo.toLowerCase();

            }/*ww  w . jav  a 2s .c o  m*/
        } else if (nType == ConnectivityManager.TYPE_WIFI) {
            netType = "wifi";
        }
    }

    return netType;
}

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;
    }//from   w  w w.j a  v a2 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 boolean isWapNet(Context context) {
    ConnectivityManager conManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = conManager.getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        if (info.getType() == 1) {
            return false;
        } else {// w w  w .j av  a2  s.c  o  m
            String currentAPN = info.getExtraInfo();
            return !TextUtils.isEmpty(currentAPN) && (currentAPN.equals("cmwap") || currentAPN.equals("uniwap")
                    || currentAPN.equals("3gwap"));
        }
    } else {
        return false;
    }
}

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 ww w.j  a  v  a2  s .com
            if (apn == null) {
                apn = "wifi";
            }
        } else {
            apn = info.getExtraInfo().toLowerCase();
            if (apn == null) {
                apn = "mobile";
            }
        }
    }
    return apn;
}

From source file:org.thoughtcrime.securesms.mms.OutgoingMmsConnection.java

public static boolean isConnectionPossible(Context context) {
    try {/* w w  w  . j  a v  a 2 s. c  o  m*/
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(MmsRadio.TYPE_MOBILE_MMS);
        if (networkInfo == null) {
            Log.w(TAG, "MMS network info was null, unsupported by this device");
            return false;
        }

        getApn(context, networkInfo.getExtraInfo());
        return true;
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        return false;
    }
}

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 {/*w ww .  j  av  a2 s.  c  om*/
        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  va  2s .  c  o m*/
                        return 3;
                    }
                }
            }
        }
    }
    return 0;
}