List of usage examples for android.net NetworkInfo getTypeName
@Deprecated
public String getTypeName()
From source file:Main.java
public static int hasActiveNetworkInfo(Context context) { int state = 0; // Assume disabled final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mActiveNetworkInfo = cm.getActiveNetworkInfo(); if (mActiveNetworkInfo != null) { String typeName = mActiveNetworkInfo.getTypeName().toLowerCase(); boolean isConnected = mActiveNetworkInfo.isConnectedOrConnecting(); int type = mActiveNetworkInfo.getType(); if ((isNetworkTypeMobile(type)) && (typeName.contains("mobile")) && isConnected) state = 2;//w w w. j a v a 2s . c om else if ((!isNetworkTypeMobile(type)) && (!typeName.contains("mobile")) && isConnected) state = 1; } return state; }
From source file:Main.java
public static String currentNetwork(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { if (info.isAvailable() && info.isConnectedOrConnecting()) { String netType = info.getTypeName(); if ("WIFI".equals(netType)) { return "WIFI"; } else { return "2G/3G"; }//from w w w . j a va2s .co m } } return null; }
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(); if (apn == null) { apn = "wifi"; }//from w w w . j ava 2 s . co m } else { apn = info.getExtraInfo().toLowerCase(); if (apn == null) { apn = "mobile"; } } } return apn; }
From source file:Main.java
public static String i(Context paramContext) { NetworkInfo localNetworkInfo = ((ConnectivityManager) paramContext.getSystemService("connectivity")) .getActiveNetworkInfo();/*from w ww. ja v a 2 s . co m*/ if (localNetworkInfo != null) { return localNetworkInfo.getTypeName(); } return "MOBILE"; }
From source file:Main.java
public static String getExtraInfo(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return null; }/* ww w . ja v a2s . c om*/ String extraInfo = nwInfo.getExtraInfo(); String typeName = nwInfo.getTypeName(); if (typeName != null && typeName.equalsIgnoreCase("WIFI")) { return typeName; } return extraInfo; }
From source file:Main.java
@SuppressWarnings({ "deprecation" }) public static String getNetWorkType(Context context) { String mNetWorkType = null;/* ww w . j a v a2 s. c o m*/ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return "ConnectivityManager not found"; } NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { String type = networkInfo.getTypeName(); if (type.equalsIgnoreCase("WIFI")) { mNetWorkType = NETWORKTYPE_WIFI; } else if (type.equalsIgnoreCase("MOBILE")) { String proxyHost = android.net.Proxy.getDefaultHost(); if (TextUtils.isEmpty(proxyHost)) { mNetWorkType = mobileNetworkType(context); } else { mNetWorkType = NETWORKTYPE_WAP; } } } else { mNetWorkType = NETWORKTYPE_INVALID; } return mNetWorkType; }
From source file:it.sasabz.android.sasabus.classes.hafas.XMLRequest.java
/** * this method checks if a network-connection is active or not * @return boolean if the network is reachable or not *//*from w ww.j a v a 2 s . c o m*/ public static boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) (SASAbus.getContext() .getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { //testing WIFI connection if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; //testing GPRS/EDGE/UMTS/HDSPA/HUSPA/LTE connection if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; }
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;/*w ww . j a v a 2 s .c o m*/ } return result; }
From source file:Main.java
static public String getMacAddress(Context context, ConnectivityManager connMananger) { Log.d(TAG, "getMacAddress"); String macAddress = ""; NetworkInfo info = connMananger.getActiveNetworkInfo(); if (info != null && info.isConnected()) { int type = info.getType(); Log.d(TAG, "connected type = " + type + " name " + info.getTypeName()); if (type == ConnectivityManager.TYPE_WIFI) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); macAddress = wifiInfo.getMacAddress(); } else if (type == ConnectivityManager.TYPE_ETHERNET || type == ConnectivityManager.TYPE_MOBILE) { String addressFileName = "/sys/class/net/eth0/address"; File addressFile = new File(addressFileName); Log.d(TAG, "1"); if (addressFile.exists()) { Log.d(TAG, "2"); macAddress = readString(addressFile); Log.d(TAG, macAddress);/*from w w w. j av a 2 s . c om*/ } else { addressFileName = "/sys/class/net/eth1/address"; addressFile = new File(addressFileName); if (addressFile.exists()) { macAddress = readString(addressFile); Log.d(TAG, macAddress); } } } else { //other type; } } return macAddress; }
From source file:com.fanfou.app.opensource.util.NetworkHelper.java
/** * ????// w w w . j av a2 s . c o m * * @param context * @param httpParams */ private static final void checkAndSetProxy(final Context context, final HttpParams httpParams) { boolean needCheckProxy = true; final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if ((networkInfo == null) || NetworkHelper.WIFI.equalsIgnoreCase(networkInfo.getTypeName()) || (networkInfo.getExtraInfo() == null)) { needCheckProxy = false; } if (needCheckProxy) { final String typeName = networkInfo.getExtraInfo(); if (NetworkHelper.MOBILE_CTWAP.equalsIgnoreCase(typeName)) { final HttpHost proxy = new HttpHost("10.0.0.200", 80); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else if (NetworkHelper.MOBILE_CMWAP.equalsIgnoreCase(typeName) || NetworkHelper.MOBILE_UNIWAP.equalsIgnoreCase(typeName) || NetworkHelper.MOBILE_3GWAP.equalsIgnoreCase(typeName)) { final HttpHost proxy = new HttpHost("10.0.0.172", 80); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } } // String defaultProxyHost = android.net.Proxy.getDefaultHost(); // int defaultProxyPort = android.net.Proxy.getDefaultPort(); // if (defaultProxyHost != null && defaultProxyHost.length() > 0 // && defaultProxyPort > 0) { // HttpHost proxy = new HttpHost(defaultProxyHost, defaultProxyPort); // httpParams.setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); // } }