List of usage examples for android.content Context CONNECTIVITY_SERVICE
String CONNECTIVITY_SERVICE
To view the source code for android.content Context CONNECTIVITY_SERVICE.
Click Source Link
From source file:Main.java
/** * @return true if there is network connection *//* w w w . ja va 2s . c o m*/ static public 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
@SuppressLint("DefaultLocale") public static boolean isWifi(Context context) { try {/*from w w w . ja v a2s. c om*/ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo nInfo = cm.getActiveNetworkInfo(); if (nInfo != null) { return nInfo.getTypeName().toUpperCase().equals("WIFI"); } } } catch (Exception e) { } return false; }
From source file:Main.java
public static boolean isNetConnected(Context context) { if (context == null) { return true; }//from ww w. ja v a 2 s .c o m ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivityManager.getActiveNetworkInfo(); if (nwInfo != null && nwInfo.isConnectedOrConnecting()) { return true; } return false; }
From source file:Main.java
public static int isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (NetworkInfo anInfo : info) { if (anInfo.getState() == NetworkInfo.State.CONNECTED) { if (anInfo.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (anInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String extraInfo = anInfo.getExtraInfo(); if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo)) { return 2; }//from w ww . ja v a 2 s . c o m return 3; } } } } } return 0; }
From source file:Main.java
public static boolean isConnected(Context mContext) { ConnectivityManager connectivityManager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return false; }/*from w ww . jav a 2s . com*/ NetworkInfo[] networkInfoList = connectivityManager.getAllNetworkInfo(); if (networkInfoList != null) { for (NetworkInfo nwInfo : networkInfoList) { if (nwInfo.isConnected()) { return true; } } } return false; }
From source file:Main.java
/** Returns true if an internet connection is available. */ public static boolean isInternetAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected(); }
From source file:Main.java
/** * is network avaliable/*from w w w . j a v a2s .c om*/ * * @param context * @return */ public static boolean isNetworkAvaliable(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; } else { return false; } }
From source file:Main.java
public static boolean isNetConnected(Context context) { if (context != null) { final ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return !(networkInfo == null || !networkInfo.isConnectedOrConnecting()); } else {/*from w w w .j a va 2s. c om*/ return false; } }
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; }// w ww .jav a2 s . c om return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
/** * Check WIFI connection.//from w w w. ja va2 s .co m * * @return */ public static boolean isWifiConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return (info != null && ConnectivityManager.TYPE_WIFI == info.getType()); }