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
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 w ww . jav a2s.c o m*/ return false; }
From source file:Main.java
/** * @param context//from w w w. j a va 2 s. com * @return */ public static final boolean isNetworkAvailable(final Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnected(); }
From source file:Main.java
private static NetworkInfo getActiveNetworkInfo(Context context) { if (context == null) { return null; }/*from w ww .j a va 2s . c om*/ ConnectivityManager connectiveManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectiveManager == null) { return null; } return connectiveManager.getActiveNetworkInfo(); }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { if (context != null) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }//from w w w .ja v a 2s. c o m NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } if (networkinfo.getState() == NetworkInfo.State.CONNECTED) { return true; } else { return false; } } return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { if (context == null) { return false; }//from w w w .j a va 2 s . c o m ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.isConnectedOrConnecting(); }
From source file:Main.java
/** * Function to check if network is available * *//* ww w.j a va 2 s . c o m*/ public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
From source file:Main.java
public static boolean checkInternetConnection(Context context) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); try {/*from ww w . j a v a 2s .c o m*/ 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; } } catch (Exception e) { e.getStackTrace(); } return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
private static ConnectivityManager getConnectivityManager(Context context) { // use application context to avoid leaking any activity // https://code.google.com/p/android/issues/detail?id=198852 return (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); }
From source file:Main.java
/** * Determine the current networking is WIFI * /*from ww w . j a v a 2 s.c om*/ * @param context * @return */ public static boolean CurrentNoteworkTypeIsWIFI(Context context) { ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
/** * Determine the current networking is WIFI * /* w w w . j ava 2 s . c om*/ * @param context * @return */ public static boolean currentNoteworkTypeIsWIFI(Context context) { ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; }