List of usage examples for android.net ConnectivityManager getActiveNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getActiveNetworkInfo()
From source file:Main.java
public static boolean ensureWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo == null || !netInfo.isConnectedOrConnecting()) return false; // always OK if we're on wifi if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) return true; // check for wifi only pref if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("wifiPref", true)) { Log.d("Podax", "Not downloading because Wifi is required and not connected"); return false; }//from w ww.j ava2 s . c o m // check for 3g data turned off if (!netInfo.isConnected()) { Log.d("Podax", "Not downloading because background data is turned off"); return false; } return true; }
From source file:Main.java
public static boolean isNetWorkAvailable(Context context) { boolean bisConnFlag = false; ConnectivityManager conManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo network = conManager.getActiveNetworkInfo(); if (network != null) { bisConnFlag = network.isAvailable(); }/*from ww w . j av a2 s .c o m*/ return bisConnFlag; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { try {//ww w . ja va2 s . co m ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager.getActiveNetworkInfo() != null && connManager.getActiveNetworkInfo().isAvailable() && connManager.getActiveNetworkInfo().isConnected()) { return true; } } catch (Exception ex) { ex.printStackTrace(); return false; } return false; }
From source file:Main.java
public static boolean checkNetwork(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = connectivity.getActiveNetworkInfo(); return (activeNetwork != null && activeNetwork.isConnected()); }
From source file:Main.java
static private int getNetType(Context context) { ConnectivityManager mConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = mConnectivity.getActiveNetworkInfo(); if (info == null) { //no connection at all return NO_CONNECTIVITY; }//from w ww .jav a2 s. c o m return info.getType(); }
From source file:Main.java
public static boolean isOnline(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean checkWifiNetwork(Context context) { boolean has = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivity.getActiveNetworkInfo(); int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { has = info.isConnected();/*w w w. ja va 2 s. c om*/ } return has; }
From source file:Main.java
public static boolean isNetworked(Context c) { // Check if we are on a network ConnectivityManager mManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo network = mManager.getActiveNetworkInfo(); if (network == null) { return false; }//ww w .j a va2s . co m if (network.isConnected()) { return true; } return false; // return (current.getState() == NetworkInfo.State.CONNECTED); }
From source file:Main.java
public static boolean isInternetOn(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfol = connectivityManager.getActiveNetworkInfo(); return networkInfol != null && networkInfol.isConnected(); }
From source file:Main.java
/** * @param context/*from w w w . ja v a 2 s . c o m*/ * @return boolean * @throws * @Title: isNetworkAvailable * @Description: TODO */ public static boolean isNetworkAvailable(Context context) { if (checkPermission(context, "android.permission.INTERNET")) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isAvailable()) { return true; } return false; } return false; }