List of usage examples for android.net NetworkInfo getType
@Deprecated public int getType()
From source file:Main.java
public static boolean isWifiConnected(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); if (mWiFiNetworkInfo != null && mWiFiNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return mWiFiNetworkInfo.isAvailable(); }/*from w w w . j a v a2 s . co m*/ } return false; }
From source file:Main.java
public static boolean isMobile(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; }//from w w w . j a va 2 s. co m return false; }
From source file:Main.java
public static boolean isWifiAvailable(Context context) { NetworkInfo[] nets = getConnManager(context).getAllNetworkInfo(); if (nets != null) { NetworkInfo[] networkInfos = nets; int length = nets.length; for (int i = 0; i < length; ++i) { NetworkInfo net = networkInfos[i]; if (net.getType() == 1) { return net.isAvailable(); }/*from w w w . j ava 2 s .c o m*/ } } return false; }
From source file:Main.java
public static boolean isMobileAvailable(Context context) { NetworkInfo[] nets = getConnManager(context).getAllNetworkInfo(); if (nets != null) { NetworkInfo[] networkInfos = nets; int length = nets.length; for (int i = 0; i < length; ++i) { NetworkInfo net = networkInfos[i]; if (net.getType() == 0) { return net.isAvailable(); }/*from w ww. j a v a 2 s. c o m*/ } } return false; }
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 {/*w w w . j a v a 2 s . c o m*/ return false; } }
From source file:Main.java
/** * get connected network type by {@link ConnectivityManager} * <p/>/*w ww. j a v a 2 s. co m*/ * such as WIFI, MOBILE, ETHERNET, BLUETOOTH, etc. * * @return {@link ConnectivityManager#TYPE_WIFI}, {@link ConnectivityManager#TYPE_MOBILE}, * {@link ConnectivityManager#TYPE_ETHERNET}... */ public static int getConnectedTypeINT(Context context) { NetworkInfo net = getConnectivityManager(context).getActiveNetworkInfo(); if (net != null) { return net.getType(); } return -1; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkINfo = cm.getActiveNetworkInfo(); if (networkINfo != null && networkINfo.isAvailable() && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; }// w w w .j av a 2s. c o m return false; }
From source file:Main.java
public static int getNetWorkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) return -1; if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { return 0; } else {// w ww. j a v a 2 s . co m return 2; } }
From source file:Main.java
/** * //from w w w.j av a 2 s . com * @param context * @return */ public static boolean isNetworkRoaming(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.w(LOG_TAG, "couldn't get connectivity manager"); } else { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null && tm.isNetworkRoaming()) { Log.d(LOG_TAG, "network is roaming"); return true; } else { Log.d(LOG_TAG, "network is not roaming"); } } else { Log.d(LOG_TAG, "not using mobile network"); } } return false; }
From source file:Main.java
public static boolean isWifiOr3G(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return false; int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS) { return info.isConnected(); } else {//from ww w.ja v a 2 s . c o m return false; } }