List of usage examples for android.net NetworkInfo isConnectedOrConnecting
@Deprecated public boolean isConnectedOrConnecting()
From source file:Main.java
public static boolean isLowBandwithNetwork(Context applicationContext) { //check for wifi ConnectivityManager connMgr = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (!wifi.isConnectedOrConnecting()) { //if no wifi, check if we are on GPRS or EDGE TelephonyManager tm = (TelephonyManager) applicationContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null && (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE || tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) { return true; }//from ww w . j a v a 2 s. co m } return false; }
From source file:Main.java
public static boolean isConnectionToMobile(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return true; }// w ww . ja v a 2 s .c o m return false; }
From source file:Main.java
public static final boolean hasConnectivity(final Context context, final int... networkTypes) { final ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (networkTypes.length == 0) for (final NetworkInfo info : connectivity.getAllNetworkInfo()) if (info.isAvailable() || info.isConnected() || info.isConnectedOrConnecting()) return true; for (final int networkType : networkTypes) if (ConnectivityManager.isNetworkTypeValid(networkType)) { final NetworkInfo info = connectivity.getNetworkInfo(networkType); if (info.isAvailable() || info.isConnected() || info.isConnectedOrConnecting()) return true; }//w w w .ja va2s . c o m return false; }
From source file:Main.java
/** * Checks if we are online. Note that an internet connection might be reported, * but but that does not necessarily mean it's usable (eg. VPN, no DNS, ...) *//*from w w w . j a v a 2 s . co m*/ public static boolean hasConnection(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo == null || !activeNetworkInfo.isConnectedOrConnecting()) return false; return true; }
From source file:Main.java
/** * Utility method to check the online status of Android device. *///from w w w . ja v a2 s. c om public static boolean isInternetAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo == null) return false; return netInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean checkNetworkConnectivity(Context context) { // get the system ConnectivityManager ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && (networkInfo.isAvailable() || networkInfo.isConnectedOrConnecting())) { if (networkInfo.getState() == NetworkInfo.State.CONNECTED) { return true; }/* w ww. j ava 2 s . com*/ // record the fact that there is live connection } return false; }
From source file:Main.java
/** * Checks if the device is currently online, works for both wifi and mobile networks. *//*from w ww.jav a 2s . 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; }
From source file:Main.java
public static boolean isconnected(Context applicationContext) { ConnectivityManager cm = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNW = cm.getActiveNetworkInfo(); boolean isConnected = false; if (activeNW != null) { isConnected = activeNW.isConnectedOrConnecting(); }// w w w .j a v a 2 s. c o m return isConnected; }
From source file:Main.java
/** * This method checks if the Network available on the device or not. * /*from w ww . j a v a2 s .c o m*/ * @param context * @return true if network available, false otherwise */ public static Boolean isNetworkAvailable(Context context) { boolean connected = false; final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { connected = true; } else if (netInfo != null && netInfo.isConnected() && cm.getActiveNetworkInfo().isAvailable()) { connected = true; } else if (netInfo != null && netInfo.isConnected()) { try { URL url = new URL("http://www.google.com"); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setConnectTimeout(3000); urlc.connect(); if (urlc.getResponseCode() == 200) { connected = true; } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else if (cm != null) { final NetworkInfo[] netInfoAll = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfoAll) { System.out.println("get network type :::" + ni.getTypeName()); if ((ni.getTypeName().equalsIgnoreCase("WIFI") || ni.getTypeName().equalsIgnoreCase("MOBILE")) && ni.isConnected() && ni.isAvailable()) { connected = true; if (connected) { break; } } } } return connected; }
From source file:Main.java
/** * Check whether Internet connection is enabled on the device * /*from www .ja va 2s . co m*/ * @param context * @return */ public static final boolean checkNetwork(Context context) { if (context != null) { boolean result = true; ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { result = false; } return result; } else { return false; } }