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
/** * Checks if Network connectivity is available to download OpenCellID data * Requires: android:name="android.permission.ACCESS_NETWORK_STATE" *///from ww w . j a va 2s .c o m public static Boolean isNetAvailable(Context context) { try { ConnectivityManager cM = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && mobileInfo != null) { return wifiInfo.isConnected() || mobileInfo.isConnected(); } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { try {/*from w ww . ja v a 2s . com*/ ConnectivityManager connMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED || connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .getState() == NetworkInfo.State.CONNECTING) { return true; } else if (connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .getState() == NetworkInfo.State.CONNECTED || connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .getState() == NetworkInfo.State.CONNECTING) { return true; } else return false; } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean isWifiAvailable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiNetworkInfo.isAvailable(); }
From source file:Main.java
private static boolean isWifiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiNetworkInfo != null && wifiNetworkInfo.isConnected(); }
From source file:Main.java
/** * method to check if internet is connected or not * * @param mContext Context/* ww w . j a v a2s. c om*/ * @return true if connected else false */ public static boolean isInternetAvailable(Context mContext) { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; } NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null && mobileNetwork.isConnected()) { return true; } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { return true; } return false; }
From source file:Main.java
public static boolean isNetworkOnline(Context context) { try {//from www .ja v a 2 s . c o m ConnectivityManager conMan = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); Log.d("DEBUG", "mobile: " + mobile + ", wifi: " + wifi); if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING || wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
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); return wifiNetworkInfo.isConnected(); }
From source file:Main.java
/** * * @return//from w w w .j a va2s .co m */ public static boolean isWIFI(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null) { return networkInfo.isConnected(); } return false; }
From source file:Main.java
/** * * @return//from w w w.jav a 2s . com */ public static boolean isMobile(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) { return networkInfo.isConnected(); } return false; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { if (context != null) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiInfo != null) { return wifiInfo.isAvailable(); }/*w w w.j a v a 2 s. c om*/ } return false; }