List of usage examples for android.net ConnectivityManager TYPE_WIFI
int TYPE_WIFI
To view the source code for android.net ConnectivityManager TYPE_WIFI.
Click Source Link
From source file:Main.java
/** * checks if there is WI-FI connection available * @param currentActivity/*from w w w. j a va 2s . c o m*/ * @return */ public static boolean isWifiInternetAvailable(Context currentActivity) { final ConnectivityManager connectivityManager = (ConnectivityManager) currentActivity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { if (networkInfo.isConnected()) { return true; } } } return false; }
From source file:Main.java
public static boolean isWiFiEnabled(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // i assume that connectivityManager cannot be null by default - because system service exists always \ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); // simplified style of writing - I like this \ return networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
/** * checks if there is WI-FI or network connection available * @param currentActivity//www .j a v a2 s . c o m * @return */ public static boolean isInternetAvailable(Context currentActivity) { final ConnectivityManager conectivityManager = (ConnectivityManager) currentActivity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { if (networkInfo.isConnected()) { return true; } } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { if (networkInfo.isConnected()) { return true; } } } return false; }
From source file:Main.java
public static int isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (NetworkInfo anInfo : info) { if (anInfo.getState() == NetworkInfo.State.CONNECTED) { if (anInfo.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (anInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String extraInfo = anInfo.getExtraInfo(); if ("cmwap".equalsIgnoreCase(extraInfo) || "cmwap:gsm".equalsIgnoreCase(extraInfo)) { return 2; }/*from w ww . jav a2 s .com*/ return 3; } } } } } return 0; }
From source file:Main.java
public static boolean isChargeFreeNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo(); return (activeNetworkInfo != null && activeNetworkInfo.isConnected() && (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)); }
From source file:Main.java
/** * Requires {@link android.Manifest.permission#ACCESS_WIFI_STATE} * and {@link android.Manifest.permission#CHANGE_WIFI_STATE} permissions. * * @param context/*www . j a va 2 s .c o m*/ * @return */ @SuppressLint("MissingPermission") public static int disconnectWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (ni != null && ni.isConnectedOrConnecting()) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int id = wm.getConnectionInfo().getNetworkId(); return wm.disconnect() ? id : -1; } return -1; }
From source file:Main.java
private static boolean isWifiConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info != null && info.isConnected()) { return true; }/*w w w. ja v a 2 s .c om*/ return false; }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { if (context == null) { return false; }//from ww w . ja v a 2 s. c o m boolean isOK = false; try { boolean isWifiOK; boolean isMobileOK; ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager == null) { return false; } NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (state == null) { return false; } if (NetworkInfo.State.CONNECTED == state) { isWifiOK = true; } else { isWifiOK = false; } state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (state == null) { return false; } if (NetworkInfo.State.CONNECTED == state) { isMobileOK = true; } else { isMobileOK = false; } if (isMobileOK || isWifiOK) { isOK = true; } } catch (Exception e) { isOK = false; } return isOK; }
From source file:Main.java
/** * Requires {@link android.Manifest.permission#ACCESS_WIFI_STATE} * and {@link android.Manifest.permission#CHANGE_WIFI_STATE} permissions. * * @param context/*from w ww. j a va 2 s.c om*/ * @return */ @SuppressLint("MissingPermission") public static void reconnectWifi(Context context, int networkId) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (ni != null) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (networkId > -1) { wm.enableNetwork(networkId, true); } } }
From source file:Main.java
/** * * @return/*from w w w .j av a 2 s. c o 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; }