List of usage examples for android.net ConnectivityManager getActiveNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getActiveNetworkInfo()
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 {/*from w ww . j av a 2 s.c o m*/ return isConnected && isWiFi; } }
From source file:Main.java
public static boolean isConnect(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; } else {/*from w w w .j a v a2 s . co m*/ return false; } }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connMgr.getActiveNetworkInfo(); if (activeInfo != null) { return activeInfo.isConnected(); }// ww w . ja v a2 s . c o m return false; }
From source file:Main.java
public static boolean checkNetwork(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo != null) { if (networkinfo.isConnected()) { return true; }/*ww w . j a va2 s . co m*/ } return false; }
From source file:Main.java
public static boolean netIsEnable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info == null) { return false; } else {//from www . j a va 2 s . c o m if (info.isAvailable()) { return true; } else { return false; } } }
From source file:Main.java
/** * Checked the network connect status./*ww w . j av a2 s. co m*/ */ public static boolean isNetworkConnected(Context context) { if (context == null) { return false; } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected()); }
From source file:Main.java
public static boolean inetAvailable(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; }//from w w w .j a v a2 s .co m return false; }
From source file:Main.java
public static boolean isOnWifiNetwork(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) { return activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; } else {// www. j av a2s . c o m return false; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo(); return (activeNetworkInfo != null && activeNetworkInfo.isConnected()); }
From source file:Main.java
public final static boolean isNetWorkConnected(Context ctx) { ConnectivityManager manager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo network = manager.getActiveNetworkInfo(); if (network != null && network.isConnected()) { if (network.getState() == NetworkInfo.State.CONNECTED) { return true; }/*from w ww .j a v a 2 s. co m*/ } return false; }