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 isMobileConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetworkInfo != null) { return mobileNetworkInfo.isAvailable(); }//from w w w. j av a 2 s. c om } return false; }
From source file:Main.java
public static boolean isMobileConnected(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // mobile 3G Data Network if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) { return false; }//from w w w . ja v a 2 s . c o m State mobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); return (mobile == State.CONNECTED || mobile == State.CONNECTING); }
From source file:Main.java
@SuppressWarnings("deprecation") public static boolean isWifiConnected(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(); }//from www . j a v a 2 s.c o m } return false; }
From source file:Main.java
public static Boolean IsMobileConnected(Context context) { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) return networkInfo.isAvailable(); }// www . j av a 2 s .com return false; }
From source file:Main.java
public static boolean isMobileConnection(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo.State mobile = null; if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) { mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); }/*from w w w . j a v a 2 s. c om*/ return (mobile != null && mobile.equals(NetworkInfo.State.CONNECTED)); }
From source file:Main.java
public static int getNetworkState(Context context) { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo wifiNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final NetworkInfo mobileNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiNetWorkInfo != null && wifiNetWorkInfo.isAvailable()) { return ConnectivityManager.TYPE_WIFI; } else if (mobileNetWorkInfo != null && mobileNetWorkInfo.isAvailable()) { return ConnectivityManager.TYPE_MOBILE; } else {/*from w ww . j ava2 s.co m*/ return -1; } }
From source file:Main.java
public static boolean isConnection3G(Context context) { ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (conMan != null) { if (conMan.getNetworkInfo(0) != null && conMan.getNetworkInfo(1) != null) { if (conMan.getNetworkInfo(0).getState() != null && conMan.getNetworkInfo(1).getState() != null) { // mobile State mobile = conMan.getNetworkInfo(0).getState(); // wifi State wifi = conMan.getNetworkInfo(1).getState(); if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) { return false; } else if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) { return true; } else { return false; }/*from ww w .j a va 2s. c o m*/ } else { return false; } } else { return false; } } else { return false; } }
From source file:Main.java
public static int getNetworkState(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // Wifi/*from ww w.j av a2 s . co m*/ NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { return NETWORN_WIFI; } // 3G state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { return NETWORN_MOBILE; } return NETWORN_NONE; }
From source file:Main.java
public static boolean check3GNetworkInfo(Context context) { try {//from ww w .j a va 2 s .com ConnectivityManager conMan = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); //mobile 3G Data Network State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); return (mobile == State.CONNECTED || mobile == State.CONNECTING); } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean isNetworkAvaliable(Context context) { boolean isNetwokAvailable = false; ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && wifiInfo.isConnected()) { isNetwokAvailable = true;//from w w w . j a va 2 s . co m } else if (mobileInfo != null && mobileInfo.isConnected()) { isNetwokAvailable = true; } else { isNetwokAvailable = false; } return isNetwokAvailable; }