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 IsMobileConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) return networkInfo.isAvailable(); }/*from w w w .j a va 2s .co m*/ return false; }
From source file:Main.java
private static boolean isConnectionFast(int type, int subType) { if (type == ConnectivityManager.TYPE_MOBILE) { switch (subType) { case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_IDEN: return false; }//from www . j a v a2 s . co m } //in doubt, assume connection is good. return true; }
From source file:Main.java
public static String getNetworkConnType(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (null == connectMgr) { return null; }/*from w ww . ja v a 2 s. c om*/ NetworkInfo info = connectMgr.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { return null; } if (info.isRoaming()) { // here is the roaming option you can change it if you want to // disable internet while roaming, just return false return null; } NetworkInfo mobileNetworkInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (null == mobileNetworkInfo) { return null; } NetworkInfo.State mobile = mobileNetworkInfo.getState(); if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) { return NETWORK_CONN_MOBILE; } NetworkInfo wifiNetworkInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (null == wifiNetworkInfo) { return null; } NetworkInfo.State wifi = wifiNetworkInfo.getState(); if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) { return NETWORK_CONN_WIFI; } return null; }
From source file:Main.java
public static boolean isNetworkAvailable(Context ctx) { int networkStatePermission = ctx.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE); if (networkStatePermission == PackageManager.PERMISSION_GRANTED) { ConnectivityManager mConnectivity = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); // Skip if no connection, or background data disabled NetworkInfo info = mConnectivity.getActiveNetworkInfo(); if (info == null) { return false; }//from w w w . ja v a 2 s . c o m // Only update if WiFi int netType = info.getType(); // int netSubtype = info.getSubtype(); if ((netType == ConnectivityManager.TYPE_WIFI) || (netType == ConnectivityManager.TYPE_MOBILE)) { return info.isConnected(); } else { return false; } } else { return true; } }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { if (context == null) { return false; }/*from w ww . j av a 2 s .co m*/ boolean isOK = false; try { boolean isWifiOK; boolean isMobileOK; ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager == null) { return false; } NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (state == null) { return false; } if (NetworkInfo.State.CONNECTED == state) { isWifiOK = true; } else { isWifiOK = false; } state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (state == null) { return false; } if (NetworkInfo.State.CONNECTED == state) { isMobileOK = true; } else { isMobileOK = false; } if (isMobileOK || isWifiOK) { isOK = true; } } catch (Exception e) { isOK = false; } return isOK; }
From source file:Main.java
public static boolean isGPRSConnected(Context context) { ConnectivityManager cmg = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); boolean result = true; NetworkInfo active = cmg.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (active == null || !active.isConnected()) { result = false;/*from w w w. j a va 2 s .com*/ } return result; }
From source file:Main.java
public static boolean isMobileAvail(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mMobileNetworkInfo != null) { return mMobileNetworkInfo.isAvailable(); }/* w w w . j av a 2 s . com*/ } return false; }
From source file:Main.java
public static boolean isUsingMobile(Context context) { ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cnm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); return ni != null && ni.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isMobile(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); return activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE; }
From source file:Main.java
public static boolean isMobile(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; }/*w w w .ja v a 2 s . c o m*/ return false; }