Java Code Examples for com.google.android.exoplayer2.C#NetworkType
The following examples show how to use
com.google.android.exoplayer2.C#NetworkType .
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 Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * 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: DefaultBandwidthMeter.java From Telegram with GNU General Public License v2.0 | 5 votes |
private long getInitialBitrateEstimateForNetworkType(@C.NetworkType int networkType) { Long initialBitrateEstimate = initialBitrateEstimates.get(networkType); if (initialBitrateEstimate == null) { initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN); } if (initialBitrateEstimate == null) { initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE; } return initialBitrateEstimate; }
Example 3
Source File: Util.java From Telegram with GNU General Public License v2.0 | 5 votes |
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 4
Source File: Util.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * 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 5
Source File: DefaultBandwidthMeter.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private long getInitialBitrateEstimateForNetworkType(@C.NetworkType int networkType) { Long initialBitrateEstimate = initialBitrateEstimates.get(networkType); if (initialBitrateEstimate == null) { initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN); } if (initialBitrateEstimate == null) { initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE; } return initialBitrateEstimate; }
Example 6
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
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 MediaSDK with Apache License 2.0 | 5 votes |
/** * 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 TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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 TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * 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 10
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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 11
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * 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 12
Source File: DefaultBandwidthMeter.java From MediaSDK with Apache License 2.0 | 5 votes |
private long getInitialBitrateEstimateForNetworkType(@C.NetworkType int networkType) { Long initialBitrateEstimate = initialBitrateEstimates.get(networkType); if (initialBitrateEstimate == null) { initialBitrateEstimate = initialBitrateEstimates.get(C.NETWORK_TYPE_UNKNOWN); } if (initialBitrateEstimate == null) { initialBitrateEstimate = DEFAULT_INITIAL_BITRATE_ESTIMATE; } return initialBitrateEstimate; }
Example 13
Source File: Util.java From MediaSDK with Apache License 2.0 | 5 votes |
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 14
Source File: DefaultBandwidthMeter.java From Telegram-FOSS with GNU General Public License v2.0 | 2 votes |
/** * Sets the initial bitrate estimate in bits per second that should be assumed when a bandwidth * estimate is unavailable and the current network connection is of the specified type. * * @param networkType The {@link C.NetworkType} this initial estimate is for. * @param initialBitrateEstimate The initial bitrate estimate in bits per second. * @return This builder. */ public Builder setInitialBitrateEstimate( @C.NetworkType int networkType, long initialBitrateEstimate) { initialBitrateEstimates.put(networkType, initialBitrateEstimate); return this; }
Example 15
Source File: DefaultBandwidthMeter.java From Telegram-FOSS with GNU General Public License v2.0 | 2 votes |
/** * Overrides the network type. Handled in the same way as if the meter had detected a change from * the current network type to the specified network type internally. * * <p>Applications should not normally call this method. It is intended for testing purposes. * * @param networkType The overriding network type. */ public synchronized void setNetworkTypeOverride(@C.NetworkType int networkType) { networkTypeOverride = networkType; networkTypeOverrideSet = true; onConnectivityAction(); }
Example 16
Source File: DefaultBandwidthMeter.java From MediaSDK with Apache License 2.0 | 2 votes |
/** * Overrides the network type. Handled in the same way as if the meter had detected a change from * the current network type to the specified network type internally. * * <p>Applications should not normally call this method. It is intended for testing purposes. * * @param networkType The overriding network type. */ public synchronized void setNetworkTypeOverride(@C.NetworkType int networkType) { networkTypeOverride = networkType; networkTypeOverrideSet = true; onConnectivityAction(); }
Example 17
Source File: DefaultBandwidthMeter.java From MediaSDK with Apache License 2.0 | 2 votes |
/** * Sets the initial bitrate estimate in bits per second that should be assumed when a bandwidth * estimate is unavailable and the current network connection is of the specified type. * * @param networkType The {@link C.NetworkType} this initial estimate is for. * @param initialBitrateEstimate The initial bitrate estimate in bits per second. * @return This builder. */ public Builder setInitialBitrateEstimate( @C.NetworkType int networkType, long initialBitrateEstimate) { initialBitrateEstimates.put(networkType, initialBitrateEstimate); return this; }
Example 18
Source File: DefaultBandwidthMeter.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Sets the initial bitrate estimate in bits per second that should be assumed when a bandwidth * estimate is unavailable and the current network connection is of the specified type. * * @param networkType The {@link C.NetworkType} this initial estimate is for. * @param initialBitrateEstimate The initial bitrate estimate in bits per second. * @return This builder. */ public Builder setInitialBitrateEstimate( @C.NetworkType int networkType, long initialBitrateEstimate) { initialBitrateEstimates.put(networkType, initialBitrateEstimate); return this; }
Example 19
Source File: DefaultBandwidthMeter.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Overrides the network type. Handled in the same way as if the meter had detected a change from * the current network type to the specified network type internally. * * <p>Applications should not normally call this method. It is intended for testing purposes. * * @param networkType The overriding network type. */ public synchronized void setNetworkTypeOverride(@C.NetworkType int networkType) { networkTypeOverride = networkType; networkTypeOverrideSet = true; onConnectivityAction(); }