List of usage examples for android.net ConnectivityManager TYPE_MOBILE
int TYPE_MOBILE
To view the source code for android.net ConnectivityManager TYPE_MOBILE.
Click Source Link
From source file:Main.java
public static String getNetworkType(ConnectivityManager connManager) { NetworkInfo networkInfo = connManager.getActiveNetworkInfo(); String networkType = null;//from w w w . j a va 2 s . c o m if (networkInfo == null) { networkType = "not connect"; } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { networkType = "wifi"; } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { networkType = "mobile"; } return networkType; }
From source file:Main.java
public static boolean hasConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; }/*from w w w. j av a 2 s .com*/ NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null && mobileNetwork.isConnected()) { return true; } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { return true; } return false; }
From source file:Main.java
public static int getNetWorkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) return -1; if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { return 0; } else {//from w ww.j a va2s . com return 2; } }
From source file:Main.java
public static boolean hasInternetAccess(Context context) { try {/*from ww w. java 2 s. c om*/ boolean hasInternet = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if ((wifi.isAvailable() || mobile.isAvailable()) && networkInfo != null && networkInfo.isConnectedOrConnecting()) { hasInternet = true; } return hasInternet; } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean checkNetworkConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifi == State.CONNECTED) { return true; }/*w w w . j ava 2 s .c om*/ State mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (mobile == State.CONNECTED) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int type = tm.getNetworkType(); if (type != TelephonyManager.NETWORK_TYPE_CDMA && type != TelephonyManager.NETWORK_TYPE_EDGE && type != TelephonyManager.NETWORK_TYPE_GPRS) { return true; } } return false; }
From source file:Main.java
/** * method to check for network availability. returns true for available and * false for unavailable/* w w w .j a va 2s . c o m*/ */ public static boolean isConnectionAvailable(Context context) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileNetwork = conn.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiNetwork != null && wifiNetwork.isAvailable() == true && wifiNetwork.isConnectedOrConnecting() == true) { return true; } else if (mobileNetwork != null && mobileNetwork.isAvailable() == true && mobileNetwork.isConnectedOrConnecting() == true) { return true; } else return false; }
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 w w w .ja v 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
@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(); }// w ww . ja v a 2s.c om } else if (nType == ConnectivityManager.TYPE_WIFI) { netType = "wifi"; } } return netType; }
From source file:Main.java
public static boolean isMobileConnected(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // mobile 3G Data Network if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) { return false; }// w w w.ja v a 2s .co m State mobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); return (mobile == State.CONNECTED || mobile == State.CONNECTING); }
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; }// w w w .j av 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; }