List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:Main.java
private static boolean isWifiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiNetworkInfo != null && wifiNetworkInfo.isConnected(); }
From source file:Main.java
public static boolean isHightBandwidthConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return (info != null && info.isConnected() && isConnectionFast(info.getType(), info.getSubtype())); }
From source file:Main.java
public static boolean HaveNetworkConnection(Context ctx) { boolean HaveConnectedWifi = false; boolean HaveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) { if (ni.isConnected()) { HaveConnectedWifi = true; }//from w w w . j a v a 2s. c o m } if (ni.getTypeName().equalsIgnoreCase("MOBILE")) { if (ni.isConnected()) { HaveConnectedMobile = true; } } } return HaveConnectedWifi || HaveConnectedMobile; }
From source file:Main.java
public static boolean checkInternetConnection(Context context) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); try {//from w w w. j av a 2s.c om NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } } catch (Exception e) { e.getStackTrace(); } return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
private static boolean isWIFIConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null) { return networkInfo.isConnected(); }//from w w w . j ava 2 s . c o m return false; }
From source file:Main.java
private static boolean isMOBILEConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) { return networkInfo.isConnected(); }/*from ww w .j a v a 2 s . c o m*/ return false; }
From source file:Main.java
public static boolean hasConnection(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; }//from w ww.jav a 2 s . c om 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 String getNetworkConnType(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (null == connectMgr) { return null; }//from w w w . ja va2 s . co m 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 isWifiConnectionAvailable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { return activeNetworkInfo.isConnected() && activeNetworkInfo.getType() == connectivityManager.TYPE_WIFI; } else {// w w w. j av a2 s . co m return false; } }
From source file:Main.java
/** * Metodo para saber si se tiene conexion a internet * por medio de datos o wifi// w ww . j av a2 s .c o m * @param context * @return */ public static boolean hasInternet(Context a) { boolean hasConnectedWifi = false; boolean hasConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase(WIFI_TYPE_NAME)) if (ni.isConnected()) hasConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase(MOBILE_TYPE_NAME)) if (ni.isConnected()) hasConnectedMobile = true; } return hasConnectedWifi || hasConnectedMobile; }