List of usage examples for android.net NetworkInfo isAvailable
@Deprecated public boolean isAvailable()
From source file:Main.java
public static boolean detect(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }/*from w w w .j a v a 2 s.com*/ NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { if (context == null) { return false; }/*w ww. j ava2s. co m*/ try { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); return info.isAvailable(); } } catch (Exception e) { return false; } return false; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { final ConnectivityManager connMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi.isAvailable()) return true; else// ww w. j av a 2s. c o m return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }//from w ww. j a v a2 s . c o m NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static boolean isAccessNetwork(Context context) { boolean result; ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netinfo = connManager.getActiveNetworkInfo(); if (netinfo != null && netinfo.isAvailable()) { result = true;/*from w ww . j ava 2s .c om*/ } else { result = false; } return result; }
From source file:Main.java
/** * This method is used to check whether Wi-Fi is connected or not. * @param appContext/*from www . ja v a 2 s .c om*/ * @return */ public static boolean isWiFiConnected(Context appContext) { boolean isConnected = false; ConnectivityManager connMgr = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi != null && wifi.isAvailable()) { isConnected = true; } return isConnected; }
From source file:Main.java
public static int getConnectedType(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isAvailable()) { return networkInfo.getType(); }/* www. j av a 2s . c o m*/ } return -1; }
From source file:Main.java
/** * Checks the devices connectivity/*w w w.j a va 2 s .c o m*/ * * @return True if connection is available, false if not */ public static boolean isConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo == null ? false : networkInfo.isAvailable(); }
From source file:Main.java
public static boolean getNetWorkState(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return false; }//from ww w . j av a 2 s .c o m NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isAvailable()) { return false; } return true; }
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; }/*from ww w .ja va 2s . co m*/ // record the fact that there is live connection } return false; }