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 boolean checkMobileInternetConn() { //Create object for ConnectivityManager class which returns network related info ConnectivityManager connectivity = (ConnectivityManager) m_TempContext .getSystemService(m_TempContext.CONNECTIVITY_SERVICE); //If connectivity object is not null if (connectivity != null) { //Get network info - Mobile internet access NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (info != null) { //Look for whether device is currently connected to Mobile internet if (info.isConnected()) { return true; }// w ww . j a v a 2 s. co m } } return false; }
From source file:Main.java
/** * Permet de verifier la connexion tablette est elle en 4 G ou non * @param pContext/* w w w. j a v a 2s . c o m*/ * @return */ public static boolean isConnectedWithData(Context pContext) { ConnectivityManager connMgr = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); return mobile.isConnectedOrConnecting(); }
From source file:Main.java
public static int getConnectivityStatus(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) return TYPE_WIFI; if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) return TYPE_MOBILE; }/*from ww w . j a v a2 s . co m*/ return TYPE_NOT_CONNECTED; }
From source file:Main.java
public static boolean isWifiOr3G(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return false; int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS) { return info.isConnected(); } else {/*from w w w.j a va2 s. c o m*/ return false; } }
From source file:Main.java
public static boolean checkGprsNetwork(Context context) { boolean has = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = connectivity.getActiveNetworkInfo(); int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) { has = info.isConnected();/*from www.j a v a2 s .c o m*/ } return has; }
From source file:Main.java
/** * This method is used to check whether GPRS is connected or not. * @param appContext//from ww w . ja va 2s .co m * @return */ public static boolean isGPRSConnected(Context appContext) { boolean isConnected = false; if (isMobileDataEnables(appContext)) { ConnectivityManager connMgr = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobile != null && mobile.isAvailable() && mobile.isConnected()) { isConnected = true; } return isConnected; } else { return isConnected; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { try {/*from w ww .j a va 2 s . co m*/ ConnectivityManager connMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED || connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .getState() == NetworkInfo.State.CONNECTING) { return true; } else if (connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .getState() == NetworkInfo.State.CONNECTED || connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .getState() == NetworkInfo.State.CONNECTING) { return true; } else return false; } catch (Exception e) { return false; } }
From source file:Main.java
/** * checks if there is network connection available * @param currentActivity/*from w w w . j a va2 s . c om*/ * @return */ public static boolean isMobileInternetAvailable(Activity currentActivity) { final ConnectivityManager connectivityManager = (ConnectivityManager) currentActivity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { if (networkInfo.isConnected()) { return true; } } } return false; }
From source file:Main.java
public static boolean hasConnection(final Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiInfo != null && wifiInfo.isConnected()) { return true; }//from w ww . j a v a 2 s .c o m wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && wifiInfo.isConnected()) { return true; } wifiInfo = cm.getActiveNetworkInfo(); if (wifiInfo != null && wifiInfo.isConnected()) { return true; } return false; }
From source file:Main.java
/** * Checks if the device is currently online, works for both wifi and mobile networks. *///from w w w .j a v a 2 s. c o m public static boolean isOnline(Context context) { if (context == null) return false; boolean state = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null) state = wifiNetwork.isConnectedOrConnecting(); NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null) state = mobileNetwork.isConnectedOrConnecting(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) state = activeNetwork.isConnectedOrConnecting(); return state; }