List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
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;/*from w w w . ja v a2s . com*/ } } return result; }
From source file:Main.java
public static boolean isWifiOr3G(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return false; int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS) { return info.isConnected(); } else {/*from w w w.j av a 2 s . c o m*/ return false; } }
From source file:Main.java
/** * Checks if Network connectivity is available to download OpenCellID data * Requires: android:name="android.permission.ACCESS_NETWORK_STATE" *//*from w w w. j a va 2 s .c o m*/ public static Boolean isNetAvailable(Context context) { try { ConnectivityManager cM = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && mobileInfo != null) { return wifiInfo.isConnected() || mobileInfo.isConnected(); } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.vinexs.tool.NetworkManager.java
public static boolean haveNetwork(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); return (netInfo != null && netInfo.isConnected()); }
From source file:Main.java
private static boolean checkNetWork_b(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(context.CONNECTIVITY_SERVICE); NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mNetworkInfo = connectMgr.getActiveNetworkInfo(); boolean bmob = mobNetInfo.isConnected(); boolean bwifi = wifiNetInfo.isConnected(); if (!bmob && !bwifi) { // Log.i(TAG, "unconnect"); // unconnect network return false; } else {/*from w ww . j a va 2s . c o m*/ // connect network return true; } }
From source file:com.frame.network.utils.NetworkUtil.java
/** * WIFI?//from w w w .ja va2 s.co m * @param context * @return */ public static boolean isWifiConnected(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.isConnected(); }
From source file:Main.java
public static String getNetworkTypeName(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo; String type = NETWORK_TYPE_DISCONNECT; if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) { return type; }// w ww. j a va 2s.c o m if (networkInfo.isConnected()) { String typeName = networkInfo.getTypeName(); if ("WIFI".equalsIgnoreCase(typeName)) { type = NETWORK_TYPE_WIFI; } else if ("MOBILE".equalsIgnoreCase(typeName)) { String proxyHost = android.net.Proxy.getDefaultHost(); type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP; } else { type = NETWORK_TYPE_UNKNOWN; } } return type; }
From source file:it.sasabz.android.sasabus.classes.hafas.XMLRequest.java
/** * this method checks if a network-connection is active or not * @return boolean if the network is reachable or not *///from w w w . j a va 2 s .c o m public static boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) (SASAbus.getContext() .getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { //testing WIFI connection if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mMobile = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); boolean flag = false; if ((mWifi != null) && ((mWifi.isAvailable()) || (mMobile.isAvailable()))) { if ((mWifi.isConnected()) || (mMobile.isConnected())) { flag = true;/*from w ww . j av a 2s . c o m*/ } } return flag; }
From source file:Main.java
public static final boolean isNetworkAvailable(Context paramContext) { ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext .getSystemService(Activity.CONNECTIVITY_SERVICE); final NetworkInfo localNetworkInfo1 = localConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); final NetworkInfo localNetworkInfo2 = localConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); return (localNetworkInfo1.isConnected() && localNetworkInfo2.isConnected()); }