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 isConnectingToInternet(Context context) { try {// w w w . j a v a 2s. c o m ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { return true; } } catch (Exception e) { e.printStackTrace(); return false; } return false; }
From source file:Main.java
private static boolean hasInternet(Context context) { boolean flag = false; ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectionManager.getActiveNetworkInfo() != null) { flag = connectionManager.getActiveNetworkInfo().isAvailable(); }// w w w. j a v a 2s.c o m return flag; }
From source file:Main.java
/** * Check network connectivity//from w w w . j ava2 s .co m * * @param context * */ public static boolean isConnected(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) return true; else return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo.isConnected()"); return true; } else {/*from w ww. j a v a 2 s . c o m*/ Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo = null"); return false; } }
From source file:Main.java
public static boolean checkInternetConnection(Context context) { ConnectivityManager con_manager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (con_manager.getActiveNetworkInfo() != null && con_manager.getActiveNetworkInfo().isAvailable() && con_manager.getActiveNetworkInfo().isConnected()) { return true; } else {/*from www . j av a 2 s . c o m*/ return false; } }
From source file:Main.java
/** * Returns true if the app is connected to the internet, meaning the network * is connected./*from w w w . jav a2 s. com*/ * * @return True if the context can connect to the internet. */ public static boolean isConnectedToInternet(Context context) { // check if we are connected to the network ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } // not connected to the network return false; }
From source file:Main.java
/** * checkout network connect/* ww w . j a va 2 s . c o m*/ * * @param context * @return */ public static boolean isNetworkConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isAvailable(); } return false; }
From source file:Main.java
/** * Check whether wifi is enabled and connected * * @param activity context//w w w . j a v a 2 s .c o m */ public static boolean isOnline(Context c) { ConnectivityManager connMgr = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected()); }
From source file:Main.java
public static boolean isConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; }//from w w w. ja v a 2 s. c o m } return false; }
From source file:Main.java
public static boolean isNetworkConnected(Context mContext) { if (mContext != null) { ConnectivityManager manager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() != null) { return (manager.getActiveNetworkInfo().isAvailable() && manager.getActiveNetworkInfo().isConnected()); }//from w ww. j ava 2 s .c om } return false; }