Java Code Examples for com.google.android.exoplayer2.C#NETWORK_TYPE_WIFI

The following examples show how to use com.google.android.exoplayer2.C#NETWORK_TYPE_WIFI . 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: Util.java    From MediaSDK with Apache License 2.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 2
Source File: Util.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
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: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 5
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 6
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 7
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 8
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 9
Source File: Util.java    From Telegram 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 10
Source File: Util.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}