List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:in.huohua.peterson.network.NetworkUtils.java
public static boolean isWifiConnected(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return mWifi.isConnected(); }
From source file:jp.co.conit.sss.sp.ex1.util.HttpUtil.java
/** * ???????/*from www . j av a2 s . c om*/ * * @param context {@code null}??? * @return {@code true}:??{@code false}:?? */ public static boolean isConnected(Context context) { if (context == null) { throw new IllegalArgumentException("'context' must not be null."); } boolean isConnectied = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) { isConnectied = true; } return isConnectied; }
From source file:Main.java
public static boolean isNetworkAvaliable(Context context) { boolean isNetwokAvailable = false; ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && wifiInfo.isConnected()) { isNetwokAvailable = true;/*from w w w .j a va 2s. co m*/ } else if (mobileInfo != null && mobileInfo.isConnected()) { isNetwokAvailable = true; } else { isNetwokAvailable = false; } return isNetwokAvailable; }
From source file:com.frame.network.utils.NetworkUtil.java
@TargetApi(11) public static boolean is4GNetwork(Context cxt) { boolean isOpened4G = false; TelephonyManager telephonyManager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE); if (Build.VERSION.SDK_INT >= 11) { isOpened4G = telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE; }//from w w w .j a va2 s .c o m boolean isMobile = false; ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); isMobile = info == null ? false : info.isConnected(); return isOpened4G && isMobile; }
From source file:Main.java
/** * This method checks if the Network available on the device or not. * /*from w w w . j ava2 s . co 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:net.line2soft.preambul.utils.Network.java
/** * Checks if a network is available.//from w w w . ja v a2s . c o m * @param ct An application context * @return True if a network is available, false else */ public static boolean checkAvailableNetwork(Context ct) { boolean result = false; ConnectivityManager cm = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { result = true; } return result; }
From source file:it.unicaradio.android.utils.NetworkUtils.java
public static boolean isConnectedToWifi(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info == null) { return false; }// w w w . j ava2 s . co m return info.isConnected(); }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager mConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = mConnectivity.getActiveNetworkInfo(); if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) { return false; } else if (ConnectivityManager.TYPE_WIFI == netInfo.getType()) { return netInfo.isConnected(); } else {/*from w w w . j a va 2s .c o m*/ return false; } }
From source file:it.unicaradio.android.utils.NetworkUtils.java
public static boolean isConnectedToMobileData(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (info == null) { return false; }/*from ww w . ja v a 2 s.c om*/ return info.isConnected(); }
From source file:com.frame.network.utils.NetworkUtil.java
/** * ??// www. ja v a2 s . co m * @param context * @return */ public static boolean isNetworkConnected(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.isConnected(); }