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 isNetworkAvailable(Context ctx) { ConnectivityManager manager = (ConnectivityManager) ctx.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }/*from www . ja v a 2s . c o m*/ NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { Object connectivityService = context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connectivityManager = (ConnectivityManager) connectivityService; if (connectivityManager == null) { return false; } else {/* w ww. j a va 2 s. c o m*/ NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo(); if (networkInfos != null && networkInfos.length > 0) { for (NetworkInfo networkInfo : networkInfos) { if (networkInfo.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
From source file:Main.java
public static boolean checkConn(Context ctx) { ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (conMgr.getNetworkInfo(conMgr.TYPE_MOBILE).isConnectedOrConnecting() || conMgr.getNetworkInfo(conMgr.TYPE_WIFI).isConnectedOrConnecting()) { Log.v(TAG, "Able to connect to the network"); return true; } else {/*from w ww .j ava 2 s . com*/ Log.e(TAG, "Unable to connect to network"); } return false; }
From source file:Main.java
public static boolean detect(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }/* w w w.ja v a 2s .co m*/ NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static boolean isNetworkConnectionAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnected(); }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] info = mgr.getAllNetworkInfo(); if (info != null) { for (NetworkInfo anInfo : info) { if (anInfo.getState() == NetworkInfo.State.CONNECTED) { return true; }//ww w . j a va2 s .c o m } } return false; }
From source file:Main.java
public static boolean isMOBILEConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.isConnected()) { return true; }//www. j a va 2 s.c o m return false; }
From source file:Main.java
public static boolean isWifiConnected(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected() && networkInfo.getTypeName().equalsIgnoreCase("WIFI"); }
From source file:Main.java
public static boolean isWifiOnline(Context context) { ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); return wifi == State.CONNECTED; }
From source file:Main.java
public static boolean isNetWorkAvilable(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo == null || !networkInfo.isAvailable(); }