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
public static boolean isWifi(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return false; int netType = info.getType(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else {/*from w w w . j a va2 s. com*/ return false; } }
From source file:Main.java
/** * method to check for network availability. returns true for available and * false for unavailable/* w w w.j a v a2s .c om*/ */ public static boolean isConnectionAvailable(Context context) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileNetwork = conn.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiNetwork != null && wifiNetwork.isAvailable() == true && wifiNetwork.isConnectedOrConnecting() == true) { return true; } else if (mobileNetwork != null && mobileNetwork.isAvailable() == true && mobileNetwork.isConnectedOrConnecting() == true) { return true; } else return false; }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connectivityManager.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; }//w w w. j av a2 s . c om return true; }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); return (activeNetInfo != null) && (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager mConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = mConnectivity.getActiveNetworkInfo(); if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) { return false; } else if (ConnectivityManager.TYPE_WIFI == netInfo.getType()) { return netInfo.isConnected(); } else {/* ww w . ja va2s . c o m*/ return false; } }
From source file:Main.java
public static boolean IsWifiConnection(Context context) { ConnectivityManager conectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { return false; }/* w w w . ja v a2 s .c o m*/ return networkInfo.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
@SuppressLint("DefaultLocale") public static String getAPN(Context context) { String apn = ""; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null) { if (ConnectivityManager.TYPE_WIFI == info.getType()) { apn = info.getTypeName();/*from ww w .ja v a2 s. c om*/ if (apn == null) { apn = "wifi"; } } else { apn = info.getExtraInfo().toLowerCase(); if (apn == null) { apn = "mobile"; } } } return apn; }
From source file:Main.java
public static boolean CheckNetworkConnect(Context context) { boolean result = false; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo ethInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET); NetworkInfo activeInfo = manager.getActiveNetworkInfo(); Log.v("networkInfo", "mobile:" + mobileInfo.isConnected() + "\n" + "wifi:" + wifiInfo.isConnected() + "\n" + "eth:" + ethInfo.isConnected() + "\n" + "active:" + activeInfo.getTypeName()); if (wifiInfo.isConnected() || ethInfo.isConnected()) { result = true;/*from ww w.j a v a 2 s.com*/ } return result; }
From source file:Main.java
public static boolean IsWifiAvailable(Context context) { ConnectivityManager m_NetConnectMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean bConnect = false; try {/*from w w w. j ava2 s. c o m*/ if (m_NetConnectMgr == null) return false; NetworkInfo info = m_NetConnectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); bConnect = (info.isAvailable() && info.isConnected()); } catch (Exception e) { return false; } return bConnect; }
From source file:Main.java
public static boolean isActiveNetworkWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; }/* w w w. j ava 2s.c o m*/ } return false; }