Package com.brightcove.player.network
Class ConnectivityMonitor
java.lang.Object
com.brightcove.player.network.ConnectivityMonitor
Connectivity monitor can be used to monitor changes to host network connectivity changes.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The contract of a listener that can receive callback notifications from theConnectivityMonitor
static @interface
List of supported network types. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int[]
An array of all supported network types. -
Method Summary
Modifier and TypeMethodDescriptionaddListener
(ConnectivityMonitor.Listener listener) Adds the specified listener to the list of listeners that will be notified when the host device's network connectivity state changes.Gets the human readable name of the current network, if connected.static ConnectivityMonitor
getInstance
(android.content.Context context) Get reference to a cached instance ofConnectivityMonitor
.boolean
Checks if the host device has an active network connection.boolean
isConnected
(int... allowedTypes) Checks if the host device is connected to the using one of the allowed network type.static boolean
isConnected
(android.net.NetworkInfo networkInfo, android.util.SparseArray<Boolean> networkEntitlements) Checks if the specified network is one of the allowed network type.boolean
isConnected
(android.util.SparseArray<Boolean> networkEntitlements) Checks if the host device is connected to the using one of the allowed network type.boolean
Checks if the active network connection is a Wi-Fi network.removeListener
(ConnectivityMonitor.Listener listener) Removes the specified listener from the list of listeners that will be notified when the host device's network connectivity state changes.
-
Field Details
-
ALL_NETWORKS
public static final int[] ALL_NETWORKSAn array of all supported network types.
-
-
Method Details
-
getInstance
Get reference to a cached instance ofConnectivityMonitor
.- Parameters:
context
- the android context.- Returns:
- reference to the connectivity monitor.
-
addListener
Adds the specified listener to the list of listeners that will be notified when the host device's network connectivity state changes. Please call
removeListener(Listener)
to free up resources.Please note that the design of the connectivity monitor intentionally discourages the practice of using anonymous objects as listeners to avoid resource leaks. The listener will be held weakly by this class. Anonymous listeners may get collected by GC immediately.
- Parameters:
listener
- reference to the listener.- Returns:
- reference to the single instance of
ConnectivityMonitor
-
removeListener
Removes the specified listener from the list of listeners that will be notified when the host device's network connectivity state changes.- Parameters:
listener
- reference to the listener.- Returns:
- reference to the single instance of
ConnectivityMonitor
-
isConnected
public boolean isConnected()Checks if the host device has an active network connection.- Returns:
- true if the host has network connection, otherwise false.
-
getActiveNetworkName
Gets the human readable name of the current network, if connected.- Returns:
- empty string if the host is not connected, otherwise the network type name.
-
isConnected
public boolean isConnected(int... allowedTypes) Checks if the host device is connected to the using one of the allowed network type.- Parameters:
allowedTypes
- array of allowed network types.- Returns:
- true if the host is connecting using an allowed network type, otherwise false.
-
isConnected
Checks if the host device is connected to the using one of the allowed network type.- Parameters:
networkEntitlements
- aSparseArray
ofConnectivityMonitor.NetworkType
andBoolean
values that indicate whether a specific network type can be used.- Returns:
- true if the host is connecting using an allowed network type, otherwise false.
-
isConnected
public static boolean isConnected(@Nullable android.net.NetworkInfo networkInfo, @NonNull android.util.SparseArray<Boolean> networkEntitlements) Checks if the specified network is one of the allowed network type.- Parameters:
networkInfo
- the current network information.networkEntitlements
- aSparseArray
ofConnectivityMonitor.NetworkType
andBoolean
values that indicate whether a specific network type can be used.- Returns:
- true if the host is connecting using an allowed network type, otherwise false.
-
isWifiConnection
public boolean isWifiConnection()Checks if the active network connection is a Wi-Fi network.- Returns:
- true if the active connection is a Wi-Fi network, otherwise false.
-