List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:Main.java
public static boolean isInternetConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) return false; boolean is_connect = false; NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { if (info.isConnected()) is_connect = true;// w w w.j a v a 2 s . c om } return is_connect; }
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
/** * Checks device for network connectivity * * @return If the device has data connectivity *//*w w w . ja va 2 s. com*/ public static boolean isNetworkAvailable(Context context) { boolean state = false; if (context != null) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { Log.i(TAG, "The device currently has data connectivity"); state = true; } else { Log.i(TAG, "The device does not currently have data connectivity"); state = false; } } return state; }
From source file:Main.java
public static boolean isConnected(Context context) { NetworkInfo net = getConnectivityManager(context).getActiveNetworkInfo(); return net != null && net.isConnected(); }
From source file:Main.java
public static boolean hasInternetConnection(Context context) { final ConnectivityManager conMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { return true; }//ww w . j a v a2 s . c o m return false; }
From source file:Main.java
public static boolean hasInternet(Activity activity) { ConnectivityManager manager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { return false; }/*from w w w. jav a 2 s. co m*/ if (info.isRoaming()) { // here is the roaming option you can change it if you want to // disable internet while roaming, just return false return true; } return true; }
From source file:Main.java
public static boolean checkNetwork(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.isConnected()) { return true; }/*from ww w . ja v a 2 s . c om*/ } return false; }
From source file:Main.java
public static boolean networkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; }/*from w w w . j a va2 s . c om*/ } } return false; }
From source file:Main.java
public static boolean isConnectedToWifi(Context context) { ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi != null && wifi.isConnected()) { return true; } else {/*from w w w.j a v a2s . com*/ return false; } }
From source file:Main.java
public static boolean isNetworkAvailable(ConnectivityManager connectivityManager) { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); }