List of usage examples for android.net NetworkInfo isAvailable
@Deprecated public boolean isAvailable()
From source file:Main.java
public static boolean isNetWorkAvailable(Context context) { boolean result = false; ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (null != connectivityManager) { networkInfo = connectivityManager.getActiveNetworkInfo(); if (null != networkInfo && networkInfo.isAvailable() && networkInfo.isConnected()) { result = true;// ww w . j av a 2s . c om } } return result; }
From source file:Main.java
public static int getNetworkState(Context context) { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo wifiNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final NetworkInfo mobileNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiNetWorkInfo != null && wifiNetWorkInfo.isAvailable()) { return ConnectivityManager.TYPE_WIFI; } else if (mobileNetWorkInfo != null && mobileNetWorkInfo.isAvailable()) { return ConnectivityManager.TYPE_MOBILE; } else {//from w w w . ja v a 2 s. c om return -1; } }
From source file:com.frame.network.utils.NetworkUtil.java
/** * ??//ww w . jav a2s. co m * @param context * @return true if the network is available, false otherwise */ public static boolean isNetworkAwailable(Context context) { if (context == null) { return false; } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) { return false; } return info.isAvailable(); }
From source file:com.frame.network.utils.NetworkUtil.java
/** * WIFI??/*w ww. ja v a2 s .co m*/ * @param context * @return */ public static boolean isWifiAwailable(Context context) { if (context == null) { return false; } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info == null) { return false; } return info.isAvailable(); }
From source file:org.openremote.android.console.net.ORNetworkCheck.java
/** * Detects the current WiFi status.//from w ww . ja va2s.c o m * * @param ctx global Android application context * * @return true if WiFi is available, false otherwise */ private static boolean canReachWifiNetwork(Context ctx) { WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); if (!wifiManager.isWifiEnabled() || wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) { Log.i(LOG_CATEGORY, "WiFi not enabled or WiFi network not detected."); return false; } NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (!wifiNetworkInfo.isAvailable()) { Log.i(LOG_CATEGORY, "Wifi network detected but wasn't available."); return false; } else { return true; } }
From source file:com.lee.sdk.utils.NetUtils.java
/** * ??(/* w w w . ja v a2 s .c om*/ * * @param context context * @return ? true */ public static boolean isNetworkConnected(Context context) { NetworkInfo networkInfo = getActiveNetworkInfo(context); // return networkInfo != null && networkInfo.isConnected(); boolean flag = networkInfo != null && networkInfo.isAvailable(); if (DEBUG) { Log.d(TAG, "isNetworkConnected, rtn: " + flag); } return flag; }
From source file:com.lee.sdk.utils.NetUtils.java
/** * wifi??//from w w w . j a v a 2 s . co m * * @param context context * @return wifi? true */ public static boolean isWifiNetworkConnected(Context context) { NetworkInfo networkInfo = getActiveNetworkInfo(context); // return networkInfo != null && networkInfo.isConnected(); boolean flag = networkInfo != null && networkInfo.isAvailable() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; if (DEBUG) { Log.d(TAG, "isWifiNetworkConnected, rtn: " + flag); } return flag; }
From source file:Main.java
/** * This method checks if the Network available on the device or not. * /* w ww .j a va 2 s . c om*/ * @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:it.evilsocket.dsploit.net.Network.java
public static boolean isWifiConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return info != null && info.isConnected() && info.isAvailable(); }
From source file:com.ccxt.whl.utils.CommonUtils.java
/** * ??// w w w . j a va2 s . c om * * @param context * @return */ public static boolean isNetWorkConnected(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); if (mNetworkInfo != null) { return mNetworkInfo.isAvailable(); } } return false; }