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 isNetworkConnected(Context mContext) { if (mContext != null) { ConnectivityManager manager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() != null) { return (manager.getActiveNetworkInfo().isAvailable() && manager.getActiveNetworkInfo().isConnected()); }//from w ww .j a v a 2 s .com } return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info == null) { return false; } else {/*from w w w. j av a 2 s . c om*/ return true; } } return false; }
From source file:Main.java
public static boolean checkConnection(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isAvailable(); }//from ww w . j a va 2s. c o m return false; }
From source file:Main.java
public static boolean isConnectionAvailable(Context ctx) { //boolean bConnection = false; ConnectivityManager connMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected(); }
From source file:Main.java
public static String getExtraInfo(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return null; }/*from w w w . j av a2 s .c om*/ String extraInfo = nwInfo.getExtraInfo(); String typeName = nwInfo.getTypeName(); if (typeName != null && typeName.equalsIgnoreCase("WIFI")) { return typeName; } return extraInfo; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { try {/*from w ww. j a va 2 s . c o m*/ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnected()) { if (ni.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } catch (Exception e) { return false; } return false; }
From source file:Main.java
public static boolean isNetConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if (info != null && info.isConnected()) { return true; }/*from w ww .j a v a 2s .co m*/ return false; }
From source file:Main.java
public static boolean isWiFiEnabled(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // i assume that connectivityManager cannot be null by default - because system service exists always \ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); // simplified style of writing - I like this \ return networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
public static boolean isNetworkEnabled(Context pContext) { boolean vResult = false; ConnectivityManager cm = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo vNetworkInfo = cm.getActiveNetworkInfo(); if (vNetworkInfo != null) { vResult = vNetworkInfo.isConnectedOrConnecting(); }/*from w w w. j av a2 s. c o m*/ return vResult; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetworkInfo.isConnected()) { return true; }/*from www. j a v a2 s .c o m*/ return false; }