List of usage examples for android.net ConnectivityManager getNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getNetworkInfo(@Nullable Network network)
From source file:Main.java
public static boolean isWifiDataEnable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isWifiDataEnable = false; isWifiDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .isConnectedOrConnecting();/*from ww w . j a va2s. c om*/ return isWifiDataEnable; }
From source file:Main.java
public static boolean isWifiAvail(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWiFiNetworkInfo != null) { return mWiFiNetworkInfo.isAvailable(); }// ww w .j a v a 2 s. c o m } return false; }
From source file:Main.java
public static boolean isMobileAvail(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mMobileNetworkInfo != null) { return mMobileNetworkInfo.isAvailable(); }//from w w w. java2 s. c o m } return false; }
From source file:Main.java
public static boolean isLowBandwithNetwork(Context applicationContext) { //check for wifi ConnectivityManager connMgr = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (!wifi.isConnectedOrConnecting()) { //if no wifi, check if we are on GPRS or EDGE TelephonyManager tm = (TelephonyManager) applicationContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null && (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE || tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) { return true; }// w w w . j ava2 s. com } return false; }
From source file:Main.java
/** * This method is used to check whether GPRS is connected or not. * @param appContext/*ww w . ja v a 2s . co m*/ * @return */ public static boolean isGPRSConnected(Context appContext) { boolean isConnected = false; if (isMobileDataEnables(appContext)) { ConnectivityManager connMgr = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobile != null && mobile.isAvailable() && mobile.isConnected()) { isConnected = true; } return isConnected; } else { return isConnected; } }
From source file:Main.java
public static boolean isMobileDataEnable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isMobileDataEnable = false; isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .isConnectedOrConnecting();//w w w. ja v a2s .c o m return isMobileDataEnable; }
From source file:Main.java
public static boolean isEthernetDataEnable(Context context) throws Exception { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isEthernetDataEnable = false; isEthernetDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET) .isConnectedOrConnecting();/*from ww w .j a va 2 s . c om*/ return isEthernetDataEnable; }
From source file:Main.java
public static boolean hasInternetAccess(Context context) { try {/*from w w w . ja va 2s .c o m*/ boolean hasInternet = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if ((wifi.isAvailable() || mobile.isAvailable()) && networkInfo != null && networkInfo.isConnectedOrConnecting()) { hasInternet = true; } return hasInternet; } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean isWifiDataEnable(Context context) throws Exception { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isWifiDataEnable = false; isWifiDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .isConnectedOrConnecting();//from ww w .j a v a2 s. c o m return isWifiDataEnable; }
From source file:Main.java
public static final boolean isNetworkAvailable(Context paramContext) { ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext .getSystemService(Activity.CONNECTIVITY_SERVICE); final NetworkInfo localNetworkInfo1 = localConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); final NetworkInfo localNetworkInfo2 = localConnectivityManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); return (localNetworkInfo1.isConnected() && localNetworkInfo2.isConnected()); }