Java Code Examples for android.net.ConnectivityManager#TYPE_WIMAX

The following examples show how to use android.net.ConnectivityManager#TYPE_WIMAX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaResourceGetter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return true if the device is on an ethernet or wifi network.
 * If anything goes wrong (e.g., permission denied while trying to access
 * the network state), returns false.
 */
@VisibleForTesting
boolean isNetworkReliable(Context context) {
    if (context.checkCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
            != PackageManager.PERMISSION_GRANTED) {
        Log.w(TAG, "permission denied to access network state");
        return false;
    }

    Integer networkType = getNetworkType(context);
    if (networkType == null) {
        return false;
    }
    switch (networkType.intValue()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
            Log.d(TAG, "ethernet/wifi connection detected");
            return true;
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_MOBILE:
        default:
            Log.d(TAG, "no ethernet/wifi connection detected");
            return false;
    }
}
 
Example 2
Source File: NetworkUtil.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Uses the provided context to determine the current connectivity status.
 *
 * @param context A context used to retrieve connection information from
 * @return A non-null value defined in {@link Status}
 */
public static Status getConnectivityStatus(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    switch (activeNetwork != null ? activeNetwork.getType() : CONST_NO_NETWORK) {
        case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_ETHERNET:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                if (cm.isActiveNetworkMetered())
                    return Status.MOBILE; // respect metered wifi networks as mobile
            return Status.WIFI;
        case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_BLUETOOTH: case ConnectivityManager.TYPE_WIMAX:
            return Status.MOBILE;
        default:
            return Status.NONE;
    }
}
 
Example 3
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the {@link C.NetworkType} of the current network connection. {@link
 * C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not
 * granted or the network connection type couldn't be determined.
 *
 * @param context A context to access the connectivity manager.
 * @return The {@link C.NetworkType} of the current network connection, or {@link
 *     C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or
 *     {@code context} is null.
 */
public static @C.NetworkType int getNetworkType(@Nullable Context context) {
  if (context == null) {
    return C.NETWORK_TYPE_UNKNOWN;
  }
  NetworkInfo networkInfo;
  try {
    ConnectivityManager connectivityManager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
      return C.NETWORK_TYPE_UNKNOWN;
    }
    networkInfo = connectivityManager.getActiveNetworkInfo();
  } catch (SecurityException e) {
    // Permission ACCESS_NETWORK_STATE not granted.
    return C.NETWORK_TYPE_UNKNOWN;
  }
  if (networkInfo == null || !networkInfo.isConnected()) {
    return C.NETWORK_TYPE_OFFLINE;
  }
  switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
      return C.NETWORK_TYPE_WIFI;
    case ConnectivityManager.TYPE_WIMAX:
      return C.NETWORK_TYPE_4G;
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
      return getMobileNetworkType(networkInfo);
    case ConnectivityManager.TYPE_ETHERNET:
      return C.NETWORK_TYPE_ETHERNET;
    default: // Ethernet, VPN, Bluetooth, Dummy.
      return C.NETWORK_TYPE_OTHER;
  }
}
 
Example 4
Source File: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the connection type for the given ConnectivityManager type and subtype.
 */
@ConnectionType
private static int convertToConnectionType(int type, int subtype) {
    switch (type) {
        case ConnectivityManager.TYPE_ETHERNET:
            return ConnectionType.CONNECTION_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return ConnectionType.CONNECTION_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return ConnectionType.CONNECTION_4G;
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionType.CONNECTION_BLUETOOTH;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (subtype) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionType.CONNECTION_2G;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionType.CONNECTION_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionType.CONNECTION_4G;
                default:
                    return ConnectionType.CONNECTION_UNKNOWN;
            }
        default:
            return ConnectionType.CONNECTION_UNKNOWN;
    }
}
 
Example 5
Source File: PicassoExecutorService.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
void adjustThreadCount(NetworkInfo info) {
  if (info == null || !info.isConnectedOrConnecting()) {
    setThreadCount(DEFAULT_THREAD_COUNT);
    return;
  }
  switch (info.getType()) {
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_WIMAX:
    case ConnectivityManager.TYPE_ETHERNET:
      setThreadCount(4);
      break;
    case ConnectivityManager.TYPE_MOBILE:
      switch (info.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_LTE:  // 4G
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
          setThreadCount(3);
          break;
        case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
          setThreadCount(2);
          break;
        case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
        case TelephonyManager.NETWORK_TYPE_EDGE:
          setThreadCount(1);
          break;
        default:
          setThreadCount(DEFAULT_THREAD_COUNT);
      }
      break;
    default:
      setThreadCount(DEFAULT_THREAD_COUNT);
  }
}
 
Example 6
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the {@link C.NetworkType} of the current network connection.
 *
 * @param context A context to access the connectivity manager.
 * @return The {@link C.NetworkType} of the current network connection.
 */
@C.NetworkType
public static int getNetworkType(Context context) {
  if (context == null) {
    // Note: This is for backward compatibility only (context used to be @Nullable).
    return C.NETWORK_TYPE_UNKNOWN;
  }
  NetworkInfo networkInfo;
  ConnectivityManager connectivityManager =
      (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (connectivityManager == null) {
    return C.NETWORK_TYPE_UNKNOWN;
  }
  try {
    networkInfo = connectivityManager.getActiveNetworkInfo();
  } catch (SecurityException e) {
    // Expected if permission was revoked.
    return C.NETWORK_TYPE_UNKNOWN;
  }
  if (networkInfo == null || !networkInfo.isConnected()) {
    return C.NETWORK_TYPE_OFFLINE;
  }
  switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
      return C.NETWORK_TYPE_WIFI;
    case ConnectivityManager.TYPE_WIMAX:
      return C.NETWORK_TYPE_4G;
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
      return getMobileNetworkType(networkInfo);
    case ConnectivityManager.TYPE_ETHERNET:
      return C.NETWORK_TYPE_ETHERNET;
    default: // VPN, Bluetooth, Dummy.
      return C.NETWORK_TYPE_OTHER;
  }
}
 
Example 7
Source File: Util.java    From android-notification-log with MIT License 5 votes vote down vote up
public static String getConnectivityType(Context context) {
	try {
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		if(cm != null) {
			NetworkInfo networkInfo = cm.getActiveNetworkInfo();
			if(networkInfo != null) {
				int type = networkInfo.getType();
				switch (type) {
					case ConnectivityManager.TYPE_BLUETOOTH: return "bluetooth";
					case ConnectivityManager.TYPE_DUMMY: return "dummy";
					case ConnectivityManager.TYPE_ETHERNET: return "ethernet";
					case ConnectivityManager.TYPE_MOBILE: return "mobile";
					case ConnectivityManager.TYPE_MOBILE_DUN: return "mobile dun";
					case ConnectivityManager.TYPE_VPN: return "vpn";
					case ConnectivityManager.TYPE_WIFI: return "wifi";
					case ConnectivityManager.TYPE_WIMAX: return "wimax";
					default: return ""+type;
				}
			} else {
				return "none";
			}
		}
	} catch (Exception e) {
		if(Const.DEBUG) e.printStackTrace();
	}
	return "undefined";
}
 
Example 8
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the {@link C.NetworkType} of the current network connection. {@link
 * C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not
 * granted or the network connection type couldn't be determined.
 *
 * @param context A context to access the connectivity manager.
 * @return The {@link C.NetworkType} of the current network connection, or {@link
 *     C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or
 *     {@code context} is null.
 */
public static @C.NetworkType int getNetworkType(@Nullable Context context) {
  if (context == null) {
    return C.NETWORK_TYPE_UNKNOWN;
  }
  NetworkInfo networkInfo;
  try {
    ConnectivityManager connectivityManager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
      return C.NETWORK_TYPE_UNKNOWN;
    }
    networkInfo = connectivityManager.getActiveNetworkInfo();
  } catch (SecurityException e) {
    // Permission ACCESS_NETWORK_STATE not granted.
    return C.NETWORK_TYPE_UNKNOWN;
  }
  if (networkInfo == null || !networkInfo.isConnected()) {
    return C.NETWORK_TYPE_OFFLINE;
  }
  switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
      return C.NETWORK_TYPE_WIFI;
    case ConnectivityManager.TYPE_WIMAX:
      return C.NETWORK_TYPE_4G;
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
      return getMobileNetworkType(networkInfo);
    case ConnectivityManager.TYPE_ETHERNET:
      return C.NETWORK_TYPE_ETHERNET;
    default: // Ethernet, VPN, Bluetooth, Dummy.
      return C.NETWORK_TYPE_OTHER;
  }
}
 
Example 9
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
public static int checkNetworkType(Context context) {
	int netType = 0;
	//连接管理对象
	ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	//获取NetworkInfo对象
	@SuppressLint("MissingPermission") NetworkInfo networkInfo = manager.getActiveNetworkInfo();
	if (networkInfo == null) {
		return netType;
	}
	switch (networkInfo.getType()) {
		case ConnectivityManager.TYPE_WIFI:
		case ConnectivityManager.TYPE_WIMAX:
		case ConnectivityManager.TYPE_ETHERNET:
			return 1;
		case ConnectivityManager.TYPE_MOBILE:
			switch (networkInfo.getSubtype()) {
				case TelephonyManager.NETWORK_TYPE_LTE:  // 4G
				case TelephonyManager.NETWORK_TYPE_HSPAP:
				case TelephonyManager.NETWORK_TYPE_EHRPD:
					return 2;
				case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
				case TelephonyManager.NETWORK_TYPE_CDMA:
				case TelephonyManager.NETWORK_TYPE_EVDO_0:
				case TelephonyManager.NETWORK_TYPE_EVDO_A:
				case TelephonyManager.NETWORK_TYPE_EVDO_B:
					return 3;
				case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
				case TelephonyManager.NETWORK_TYPE_EDGE:
					return 4;
				default:
					return netType;
			}

		default:
			return netType;
	}
}
 
Example 10
Source File: NetworkChangeNotifierAutoDetect.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the connection type for the given ConnectivityManager type and subtype.
 */
@ConnectionType
private static int convertToConnectionType(int type, int subtype) {
    switch (type) {
        case ConnectivityManager.TYPE_ETHERNET:
            return ConnectionType.CONNECTION_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return ConnectionType.CONNECTION_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return ConnectionType.CONNECTION_4G;
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionType.CONNECTION_BLUETOOTH;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (subtype) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionType.CONNECTION_2G;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionType.CONNECTION_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionType.CONNECTION_4G;
                default:
                    return ConnectionType.CONNECTION_UNKNOWN;
            }
        default:
            return ConnectionType.CONNECTION_UNKNOWN;
    }
}
 
Example 11
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 * 
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
            }
    }
}
 
Example 12
Source File: Network.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Check if the connection is fast
 *
 * @param type    of connection
 * @param subType of connection
 * @return true if the connection is 3g or above
 */
public static boolean isConnectionFast(final int type, final int subType) {

    switch (type) {

        case ConnectivityManager.TYPE_WIFI:
            return true;

        case ConnectivityManager.TYPE_WIMAX:
            return true;

        case ConnectivityManager.TYPE_MOBILE:

            switch (subType) {

                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return false; // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return false; // ~ 14-64 kbps
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return false; // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return true; // ~ 400-1000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return true; // ~ 600-1400 kbps
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return false; // ~ 100 kbps
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return true; // ~ 2-14 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return true; // ~ 700-1700 kbps
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return true; // ~ 1-23 Mbps
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return true; // ~ 400-7000 kbps
                case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                    return true; // ~ 1-2 Mbps
                case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                    return true; // ~ 5 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                    return true; // ~ 10-20 Mbps
                case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                    return false; // ~25 kbps
                case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                    return true; // ~ 10+ Mbps
                // Unknown
                case TelephonyManager.NETWORK_TYPE_UNKNOWN:

                default:
                    return false;
            }

        default:
            return false;

    }
}
 
Example 13
Source File: Network.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Is the device 4g capable
 *
 * @param ctx the application Context
 * @return true if the device has the capability
 */
@SuppressWarnings("deprecation")
public static boolean isFourGCapable(final Context ctx) {

    final ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

    final NetworkInfo[] info = cm.getAllNetworkInfo();

    for (int i = 0; i < info.length - 1; i++) {

        if (info[i].getType() == ConnectivityManager.TYPE_WIMAX) {
            return true;
        }

    }

    return false;
}
 
Example 14
Source File: ConnectivityWire.java    From tinybus with Apache License 2.0 4 votes vote down vote up
private void calculateConnectionType() {
	if (mConnected) {
		
		switch (mNetworkInfo.getType()) {
			case ConnectivityManager.TYPE_WIFI:
			case ConnectivityManager.TYPE_WIMAX:
			case ConnectivityManager.TYPE_ETHERNET:
				mConnectionType = CONNECTION_TYPE_FAST;
				break;
				
			case ConnectivityManager.TYPE_MOBILE:
				switch (mNetworkInfo.getSubtype()) {
					case TelephonyManager.NETWORK_TYPE_LTE:
					case TelephonyManager.NETWORK_TYPE_HSPAP:
					case TelephonyManager.NETWORK_TYPE_HSPA:
					case TelephonyManager.NETWORK_TYPE_EHRPD:
						mConnectionType = CONNECTION_TYPE_4G;
						break;
						
					case TelephonyManager.NETWORK_TYPE_UMTS:
					case TelephonyManager.NETWORK_TYPE_CDMA:
					case TelephonyManager.NETWORK_TYPE_HSDPA:
					case TelephonyManager.NETWORK_TYPE_HSUPA:
					case TelephonyManager.NETWORK_TYPE_EVDO_0:
					case TelephonyManager.NETWORK_TYPE_EVDO_A:
					case TelephonyManager.NETWORK_TYPE_EVDO_B:
						mConnectionType = CONNECTION_TYPE_3G;
						break;
						
					case TelephonyManager.NETWORK_TYPE_GPRS:
					case TelephonyManager.NETWORK_TYPE_EDGE:
						mConnectionType = CONNECTION_TYPE_2G;
						break;
						
					default:
						mConnectionType = CONNECTION_TYPE_UNKNOWN;
				}
				break;
				
			default:
				mConnectionType = CONNECTION_TYPE_UNKNOWN;
		}				
		
	} else {
		mConnectionType = CONNECTION_TYPE_UNKNOWN;
	}
}
 
Example 15
Source File: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the connection subtype for the given NetworkState.
 */
public int getConnectionSubtype() {
    if (!isConnected()) {
        return ConnectionSubtype.SUBTYPE_NONE;
    }

    switch (getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (getNetworkSubType()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return ConnectionSubtype.SUBTYPE_GPRS;
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return ConnectionSubtype.SUBTYPE_EDGE;
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return ConnectionSubtype.SUBTYPE_CDMA;
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return ConnectionSubtype.SUBTYPE_1XRTT;
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionSubtype.SUBTYPE_IDEN;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return ConnectionSubtype.SUBTYPE_UMTS;
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_0;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_A;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return ConnectionSubtype.SUBTYPE_HSDPA;
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return ConnectionSubtype.SUBTYPE_HSUPA;
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return ConnectionSubtype.SUBTYPE_HSPA;
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_B;
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return ConnectionSubtype.SUBTYPE_EHRPD;
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionSubtype.SUBTYPE_HSPAP;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionSubtype.SUBTYPE_LTE;
                default:
                    return ConnectionSubtype.SUBTYPE_UNKNOWN;
            }
        default:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
    }
}
 
Example 16
Source File: DownloaderService.java    From QtAndroidTools with MIT License 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 *
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            mIsAtLeast4G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            mIsAtLeast4G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
            }
    }
}
 
Example 17
Source File: EasyNetworkMod.java    From easydeviceinfo with Apache License 2.0 4 votes vote down vote up
/**
 * Gets network type.
 *
 * You need to declare the below permission in the manifest file to use this properly
 *
 * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 * <uses-permission android:name="android.permission.INTERNET"/>
 *
 * @return the network type
 */
@RequiresPermission(allOf = {
    Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.INTERNET
})
@NetworkType
public final int getNetworkType() {
  int result = NetworkType.UNKNOWN;
  if (PermissionUtil.hasPermission(context, Manifest.permission.ACCESS_NETWORK_STATE)) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (cm != null) {
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      if (activeNetwork == null) {
        result = NetworkType.UNKNOWN;
      } else if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI
          || activeNetwork.getType() == ConnectivityManager.TYPE_WIMAX) {
        result = NetworkType.WIFI_WIFIMAX;
      } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
        TelephonyManager manager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        if (manager != null && manager.getSimState() == TelephonyManager.SIM_STATE_READY) {
          switch (manager.getNetworkType()) {

            // Unknown
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
              result = NetworkType.CELLULAR_UNKNOWN;
              break;
            // Cellular Data 2G
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_IDEN:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
              result = NetworkType.CELLULAR_2G;
              break;
            // Cellular Data 3G
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
              result = NetworkType.CELLULAR_3G;
              break;
            // Cellular Data 4G
            case TelephonyManager.NETWORK_TYPE_LTE:
              result = NetworkType.CELLULAR_4G;
              break;
            // Cellular Data Unknown Generation
            default:
              result = NetworkType.CELLULAR_UNIDENTIFIED_GEN;
              break;
          }
        }
      }
    }
  }
  return result;
}
 
Example 18
Source File: NetworkChangeNotifierAutoDetect.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public int getCurrentConnectionType() {
    // Track exactly what type of connection we have.
    if (!mConnectivityManagerDelegate.activeNetworkExists() ||
            !mConnectivityManagerDelegate.isConnected()) {
        return NetworkChangeNotifier.CONNECTION_NONE;
    }

    switch (mConnectivityManagerDelegate.getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
            return NetworkChangeNotifier.CONNECTION_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return NetworkChangeNotifier.CONNECTION_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return NetworkChangeNotifier.CONNECTION_4G;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (mConnectivityManagerDelegate.getNetworkSubtype()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NetworkChangeNotifier.CONNECTION_2G;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return NetworkChangeNotifier.CONNECTION_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetworkChangeNotifier.CONNECTION_4G;
                default:
                    return NetworkChangeNotifier.CONNECTION_UNKNOWN;
            }
        default:
            return NetworkChangeNotifier.CONNECTION_UNKNOWN;
    }
}
 
Example 19
Source File: DownloaderService.java    From travelguide with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 * 
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            mIsAtLeast4G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            mIsAtLeast4G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
            }
    }
}
 
Example 20
Source File: AppNetworkMgr.java    From AndroidWallet with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 判断当前网络的类型是否是Wimax
 *
 * @param context 上下文
 * @return 当前网络的类型是否是Wimax。false:当前没有网络连接或者网络类型不是Wimax
 */
public static boolean isWimaxByType(Context context) {
    return getCurrentNetworkType(context) == ConnectivityManager.TYPE_WIMAX;
}