List of usage examples for android.net NetworkInfo getTypeName
@Deprecated
public String getTypeName()
From source file:Main.java
public static String getNetworkTypeName(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo; String type = NETWORK_TYPE_DISCONNECT; if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) { return type; }// ww w . java 2 s.c o m if (networkInfo.isConnected()) { String typeName = networkInfo.getTypeName(); if ("WIFI".equalsIgnoreCase(typeName)) { type = NETWORK_TYPE_WIFI; } else if ("MOBILE".equalsIgnoreCase(typeName)) { String proxyHost = android.net.Proxy.getDefaultHost(); type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP; } else { type = NETWORK_TYPE_UNKNOWN; } } return type; }
From source file:com.cloverstudio.spika.SpikaApp.java
/** * Checks whether this app has mobile or wireless connection * /* w w w .j a v a 2 s . com*/ * @return */ public static boolean hasNetworkConnection() { boolean hasConnectedWifi = false; boolean hasConnectedMobile = false; final ConnectivityManager connectivityManager = (ConnectivityManager) sInstance .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo[] netInfo = connectivityManager.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) hasConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) hasConnectedMobile = true; } boolean hasNetworkConnection = hasConnectedWifi || hasConnectedMobile; return hasNetworkConnection; }
From source file:Main.java
/** * Get network type name/*from w w w . j av a 2 s . c o m*/ * * @param context * @return boolean */ public static String getNetworkTypeName(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo; String type = NETWORK_TYPE_DISCONNECT; if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) { return type; } ; if (networkInfo.isConnected()) { String typeName = networkInfo.getTypeName(); if ("WIFI".equalsIgnoreCase(typeName)) { type = NETWORK_TYPE_WIFI; } else if ("MOBILE".equalsIgnoreCase(typeName)) { String proxyHost = android.net.Proxy.getDefaultHost(); type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP; } else { type = NETWORK_TYPE_UNKNOWN; } } return type; }
From source file:Main.java
public static String getNetworkTypeName(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo; String type = NETWORK_TYPE_DISCONNECT; if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) { return type; }//from ww w . j ava2s . c om if (networkInfo.isConnected()) { String typeName = networkInfo.getTypeName(); if ("WIFI".equalsIgnoreCase(typeName)) { type = NETWORK_TYPE_WIFI; } else if ("MOBILE".equalsIgnoreCase(typeName)) { //String proxyHost = android.net.Proxy.getDefaultHost();//deprecated String proxyHost = System.getProperty("http.proxyHost"); type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP; } else { type = NETWORK_TYPE_UNKNOWN; } } return type; }
From source file:com.dmsl.anyplace.utils.NetworkUtils.java
public static boolean haveNetworkConnection(Activity activity) { boolean haveWifi = false; boolean haveMobile = false; ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni != null && ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnectedOrConnecting()) haveWifi = true;/*from w ww .ja v a 2s . co m*/ if (ni != null && ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnectedOrConnecting()) haveMobile = true; } return haveMobile || haveWifi; }
From source file:Main.java
public static Map<String, String> getNetworkInfo(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Map<String, String> map = new HashMap(); NetworkInfo info = cm.getActiveNetworkInfo(); if ((info == null) || (!info.isConnectedOrConnecting()) || (withinInBlackList())) { map.put("access_subtype", "offline"); map.put("access", "offline"); map.put("carrier", ""); } else {/*ww w . j a v a2s . c om*/ map.put("access_subtype", info.getSubtypeName()); map.put("access", cleanNetworkTypeName(info.getTypeName())); TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String carrierName = manager.getNetworkOperatorName(); map.put("carrier", carrierName); } return map; }
From source file:org.kontalk.util.SystemUtils.java
/** Returns the type name of the current network, or null. */ public static String getCurrentNetworkName(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connMgr.getActiveNetworkInfo(); return info != null ? info.getTypeName() : null; }
From source file:com.normalexception.app.rx8club.html.LoginFactory.java
/** * Check to see if a network connection exists * @return True if network connection exists *//*from ww w. j a v a2s. c o m*/ public static boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; boolean haveConnectedEth = false; Log.d(TAG, "Checking available network connections"); ConnectivityManager cm = (ConnectivityManager) MainApplication.getAppContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { Log.d(TAG, String.format("%s is %sconnected", ni.getTypeName(), ni.isConnected() ? "" : "not ")); if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_WIFI)) if (ni.isConnected()) { Log.d(TAG, "Wifi Connection Detected"); haveConnectedWifi = true; } if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_MOBILE)) if (ni.isConnected()) { Log.d(TAG, "Mobile Connection Detected"); haveConnectedMobile = true; } if (ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_ETH) || ni.getTypeName().equalsIgnoreCase(LoginFactory.NETWORK_ETHERNET)) if (ni.isConnected()) { Log.d(TAG, "Ethernet Connection Detected"); haveConnectedEth = true; } } return haveConnectedWifi || haveConnectedMobile || haveConnectedEth; }
From source file:com.wbtech.common.CommonUtil.java
/** * ? ?wifi// ww w . j av a 2s .co m * @param context * @return */ public static boolean isNetworkTypeWifi(Context context) { // TODO Auto-generated method stub if (checkPermissions(context, "android.permission.INTERNET")) { ConnectivityManager cManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cManager.getActiveNetworkInfo(); if (info != null && info.isAvailable() && info.getTypeName().equals("WIFI")) { return true; } else { if (UmsConstants.DebugMode) { Log.e("error", "Network not wifi"); } return false; } } else { if (UmsConstants.DebugMode) { Log.e(" lost permission", "lost----> android.permission.INTERNET"); } return false; } }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static String getNetworkInfo(Context c) { String ret = getNetworkInterfaces(); ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); if (conman == null) ret += "No Connectivity?\n"; else {//from w ww .jav a2 s . c o m ret += "Connectivity Info:\n" + conman.toString() + "\n"; for (NetworkInfo ni : conman.getAllNetworkInfo()) { if (!ni.isAvailable()) continue; ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n"; } } try { WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); if (wifi == null) ret += "No wifi\n"; else { ret += "Wifi Info:\n" + wifi.toString() + "\n"; ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n"; ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac=" + wifi.getConnectionInfo().getMacAddress() + "/ " + "b=" + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID(); DhcpInfo dh = wifi.getDhcpInfo(); if (dh == null) ret += "No DHCP\n"; else { ret += "IP: " + getReadableIP(dh.ipAddress) + "\n"; ret += "Gateway: " + getReadableIP(dh.gateway) + "\n"; ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n"; } } } catch (SecurityException sec) { ret += "No Wifi permissions.\n"; } return ret; }