List of usage examples for android.net NetworkInfo isConnectedOrConnecting
@Deprecated public boolean isConnectedOrConnecting()
From source file:Main.java
public static boolean isNetworkEnabled(Context pContext) { boolean vResult = false; ConnectivityManager cm = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo vNetworkInfo = cm.getActiveNetworkInfo(); if (vNetworkInfo != null) { vResult = vNetworkInfo.isConnectedOrConnecting(); }/* w w w.j av a2 s .c o m*/ return vResult; }
From source file:Main.java
public static boolean isNetworkOn(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isConnection(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return true; }//from w w w. j av a2s. co m return false; }
From source file:Main.java
public static Boolean isNetworkAvailable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean checkConnection(Context context, boolean onlyWiFi) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); boolean isWiFi = activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; if (!onlyWiFi) { return isConnected; } else {/* w ww . j av a2s.com*/ return isConnected && isWiFi; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting(); }
From source file:Main.java
/** * Requires {@link android.Manifest.permission#ACCESS_WIFI_STATE} * and {@link android.Manifest.permission#CHANGE_WIFI_STATE} permissions. * * @param context// w ww . j a va2s . com * @return */ @SuppressLint("MissingPermission") public static int disconnectWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (ni != null && ni.isConnectedOrConnecting()) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int id = wm.getConnectionInfo().getNetworkId(); return wm.disconnect() ? id : -1; } return -1; }
From source file:Main.java
/** * Determine the network connection/*from w w w. ja v a2 s. c o m*/ * * @param context * the Context * @return TRUE if network connect is establishing */ public static boolean isConnect(Context context) { // Checking network configuration ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean is4G(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.isConnectedOrConnecting()) { if (activeNetInfo.getType() == TelephonyManager.NETWORK_TYPE_LTE) { return true; }/*from w w w .j a v a 2 s . com*/ } return false; }
From source file:Main.java
public static boolean isConnectInternet(Context context) { ConnectivityManager conManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = conManager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isConnectedOrConnecting(); }/* www .j av a 2s. c o m*/ return false; }