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 isConnectedRoaming(Context context) { ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobile != null && mobile.isConnected() && mobile.isRoaming()) { return true; } else {//from w w w . ja 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; }// w ww . j av a2 s. c o m return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mobile.isConnected() || wifi.isConnected()) { return true; } else {/* w w w . j a v a 2 s . c o m*/ return false; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mMobile = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); boolean flag = false; if ((mWifi != null) && ((mWifi.isAvailable()) || (mMobile.isAvailable()))) { if ((mWifi.isConnected()) || (mMobile.isConnected())) { flag = true;/*w ww.ja va 2 s. c o m*/ } } return flag; }
From source file:Main.java
private static boolean isMOBILEConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) { return networkInfo.isConnected(); }/* w w w .j a v a 2 s.com*/ return false; }
From source file:Main.java
public static boolean isWifiAvailable(Context context) { ConnectivityManager mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); boolean flag = false; if ((mWifi != null) && ((mWifi.isAvailable()))) { if ((mWifi.isConnected())) { flag = true;//from w w w . j a v a2 s . c om } } return flag; }
From source file:Main.java
public static NetworkInfo.State getWifiConnectState(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWiFiNetworkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWiFiNetworkInfo != null) { return mWiFiNetworkInfo.getState(); }//from www .ja v a 2 s .co m return NetworkInfo.State.DISCONNECTED; }
From source file:Main.java
public static boolean checkNetworkConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifi == State.CONNECTED) { return true; }/*ww w .ja va2 s .c om*/ State mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (mobile == State.CONNECTED) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int type = tm.getNetworkType(); if (type != TelephonyManager.NETWORK_TYPE_CDMA && type != TelephonyManager.NETWORK_TYPE_EDGE && type != TelephonyManager.NETWORK_TYPE_GPRS) { return true; } } return false; }
From source file:Main.java
private static boolean isWIFIConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null) { return networkInfo.isConnected(); }/*from w w w . ja v a2 s .co m*/ return false; }
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 . j a va2 s . c o m return false; }