List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:Main.java
public static boolean isURLConnectable(Context context, String url) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { try {// www .ja v a 2 s.co m HttpURLConnection urlc = (HttpURLConnection) new URL(url).openConnection(); urlc.setConnectTimeout(10 * 1000); // 10 s. urlc.connect(); if (urlc.getResponseCode() == 200) { // 200 = "OK" code (http // connection is fine). Log.wtf("Connection", "Success !"); return true; } else { return false; } } catch (MalformedURLException e1) { return false; } catch (IOException e) { return false; } } return false; }
From source file:Main.java
public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = (cm != null) ? cm.getActiveNetworkInfo() : null; if (info != null && info.isAvailable() && info.isConnected()) { return true; }/*from w w w . java2s. co m*/ return false; }
From source file:Main.java
public static boolean isNetConnected(Context context) { boolean connected = false; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null) { connected = networkInfo.isConnected(); }//ww w .ja va 2 s. c o m return connected; }
From source file:Main.java
public static boolean isNetworkAvailable(ConnectivityManager cm) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; NetworkInfo[] mNetInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : mNetInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }/*from www . j av a 2 s. com*/ return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
public static boolean checkStatusWifi(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi != null) { return wifi.isConnected(); } else/* ww w .j av a 2s .c om*/ 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.isConnected(); }
From source file:Main.java
/** * //from w w w.jav a 2s . c o m * @return */ public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); }
From source file:Main.java
public static boolean isWIFIConnected(Context context) { if (null == context) return false; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.isConnected()) { return true; }//from www . j a v a 2 s . c o m return false; }
From source file:Main.java
public static boolean isNetworkAvailable(ConnectivityManager obj) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = obj;/* w w w . j av a 2s .com*/ NetworkInfo[] mNetInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : mNetInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
public static boolean haveNetworkConnection(Context context) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }/*from w w w. j a v a2s. c om*/ return haveConnectedWifi || haveConnectedMobile; }