List of usage examples for android.net NetworkInfo getType
@Deprecated public int getType()
From source file:Main.java
public static boolean isMobile(Context context) { final ConnectivityManager connMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return (networkInfo != null) && (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE); }
From source file:Main.java
public static boolean checkNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; } else {// w w w. java 2 s .c o m NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { NetworkInfo netWorkInfo = info[i]; if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } } } } } return false; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { NetworkInfo net = getConnManager(context).getActiveNetworkInfo(); return net != null && net.getType() == 1 && net.isConnected(); }
From source file:Main.java
public static boolean isMobileConnected(Context context) { NetworkInfo net = getConnManager(context).getActiveNetworkInfo(); return net != null && net.getType() == 0 && net.isConnected(); }
From source file:Main.java
public static boolean isOnWIFI(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.isConnectedOrConnecting() && ni.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
/** * Check if there is any connectivity to a Wifi network. * <p/>//from ww w .j a v a2s . c o m * Can be used in combination with {@link #isConnectedMobile} * to provide different features if the device is on a wifi network or a cell network. * * @param context The current Context or Activity that this method is called from * @return true if a wifi connection is available, otherwise false. */ public static boolean isConnectedWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI); }
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. ja va 2s. co m*/ } return has; }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connectivityManager.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; }/*from w w w . j a v a2s.co m*/ return true; }
From source file:Main.java
public static boolean isMobileConnected(Context context) { NetworkInfo net = getConnectivityManager(context).getActiveNetworkInfo(); return net != null && net.getType() == ConnectivityManager.TYPE_MOBILE && net.isConnected(); }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (null == cm) { return false; }//w ww. ja v a 2s. co m NetworkInfo info = cm.getActiveNetworkInfo(); if (null != info) { if (info.getType() == ConnectivityManager.TYPE_WIFI) { return true; } } return false; }