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 isWifiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetworkInfo.isConnected()) return true; return false; }
From source file:Main.java
public static boolean isWifiDataEnable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo == null) return false; return networkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isMobileDataEnable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo == null) return false; return networkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isMobileConnected(Context context) { if (context != null) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileInfo != null) { return mobileInfo.isAvailable(); }// w w w . j a va 2 s .co m } 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); if (wifiNetworkInfo.isConnected()) { return true; }//from w w w. j a va2 s. c om return false; }
From source file:Main.java
public static int getNetworkType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State mobileState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifiState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifiState == State.CONNECTED || wifiState == State.CONNECTING) { return 1; } else if (mobileState == State.CONNECTED || mobileState == State.CONNECTING) { return 2; } else {//from w w w .j a v a 2 s . c o m return 0; } }
From source file:Main.java
public static String getCurrentSsid(Context context) { String ssid = null;/* ww w.ja v a2s. co m*/ ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && connectionInfo.getSSID() != null && !connectionInfo.getSSID().equals("")) { ssid = connectionInfo.getSSID(); } } return ssid == null ? ssid : ssid.replace("\"", ""); }
From source file:Main.java
public static boolean checkWifyNetworkInfo(Context context) { try {//from w w w . ja v a 2 s. c om ConnectivityManager conMan = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); //wifi State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); return (wifi == State.CONNECTED || wifi == State.CONNECTING); } catch (Exception e) { return true; } }
From source file:Main.java
public static boolean isWifiReady(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); String ssid = getWifiSSID(context); if (info.isConnected() && ssid != null && !"".equals(ssid)) { return true; } else {/* ww w .j a va 2 s . c o m*/ return false; } }
From source file:Main.java
public static final boolean hasWifiConnection(Context context) { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return (networkInfo != null && networkInfo.isAvailable()); }