Android Guides | Samples

Android.Net.ConnectivityManager Class

Class that answers queries about the state of network connectivity.

See Also: ConnectivityManager

Syntax

[Android.Runtime.Register("android/net/ConnectivityManager", DoNotGenerateAcw=true)]
public class ConnectivityManager : Object

Remarks

Class that answers queries about the state of network connectivity. It also notifies applications when network connectivity changes. Get an instance of this class by calling Context.GetSystemService(String).

The primary responsibilities of this class are to:

  1. Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)
  2. Send broadcast intents when network connectivity changes
  3. Attempt to "fail over" to another network when connectivity to a network is lost
  4. Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks
  5. Provide an API that allows applications to request and select networks for their data traffic

[Android Documentation]

Requirements

Namespace: Android.Net
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Net.ConnectivityManager are listed below.

See Also: Object

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
ActionBackgroundDataSettingChangedString. Broadcast Action: The setting for background data usage has changed values.
const
ConnectivityActionString. A change in network connectivity has occurred.
const
DefaultNetworkPreferenceInt32 (1). If you want to set the default network preference,you can directly change the networkAttributes array in framework's config.xml.
const
ExtraExtraInfoString. The lookup key for a string that provides optionally supplied extra information about the network state.
const
ExtraIsFailoverString. The lookup key for a boolean that indicates whether a connect event is for a network to which the connectivity manager was failing over following a disconnect on another network.
const
ExtraNetworkInfoString. The lookup key for a NetworkInfo object.
const
ExtraNetworkTypeString. Network type which triggered a ConnectivityManager.ConnectivityAction broadcast.
const
ExtraNoConnectivityString. The lookup key for a boolean that indicates whether there is a complete lack of connectivity, i.e., no network is available.
const
ExtraOtherNetworkInfoString. The lookup key for a NetworkInfo object.
const
ExtraReasonString. The lookup key for a string that indicates why an attempt to connect to a network failed.

Public Properties

[read-only]
ActiveNetworkInfoNetworkInfo. Returns details about the currently active default data network.
[read-only]
BackgroundDataSettingBoolean. Returns the value of the setting for background data usage.
[read-only]
IsActiveNetworkMeteredBoolean. Returns if the currently active data network is metered.
[read-only]
IsDefaultNetworkActiveBoolean. Return whether the data network is currently active.
NetworkPreferenceConnectivityType. Retrieves the current preferred network type.
[read-only]
static
ProcessDefaultNetworkNetwork. Returns the Network currently bound to this process via ConnectivityManager.BindProcessToNetwork(Network), or null if no Network is explicitly bound.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AddDefaultNetworkActiveListener(ConnectivityManager+IOnNetworkActiveListener)
Start listening to reports when the system's default data network is active, meaning it is a good time to perform network traffic.
static
FromContext(Context) : ConnectivityManager
GetAllNetworkInfo() : NetworkInfo[]
Returns connection status information about all network types supported by the device.
GetAllNetworks() : Network[]
Returns an array of all Network currently tracked by the framework.
GetLinkProperties(Network) : LinkProperties
Get the LinkProperties for the given Network.
GetNetworkCapabilities(Network) : NetworkCapabilities
Get the NetworkCapabilities for the given Network.
GetNetworkInfo(ConnectivityType) : NetworkInfo
Returns connection status information about a particular network type.
GetNetworkInfo(Network) : NetworkInfo
Returns connection status information about a particular Network.
static
IsNetworkTypeValid(ConnectivityType) : Boolean
Tests if a given integer represents a valid network type.
RegisterNetworkCallback(NetworkRequest, ConnectivityManager+NetworkCallback)
Registers to receive notifications about all networks which satisfy the given NetworkRequest.
RemoveDefaultNetworkActiveListener(ConnectivityManager+IOnNetworkActiveListener)
Remove network active listener previously registered with ConnectivityManager.AddDefaultNetworkActiveListener(.IOnNetworkActiveListener).
ReportBadNetwork(Network)
Report a problem network to the framework.
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback)
Request a network to satisfy a set of NetworkCapabilities.
RequestRouteToHost(ConnectivityType, Int32) : Boolean
Ensure that a network route exists to deliver traffic to the specified host via the specified network interface.
RequestRouteToHostAsync(ConnectivityType, Int32) : System.Threading.Tasks.Task<bool>
static
SetProcessDefaultNetwork(Network) : Boolean
Binds the current process to network.
StartUsingNetworkFeature(ConnectivityType, String) : Int32
Tells the underlying networking system that the caller wants to begin using the named feature.
StopUsingNetworkFeature(ConnectivityType, String) : Int32
Tells the underlying networking system that the caller is finished using the named feature.
UnregisterNetworkCallback(ConnectivityManager+NetworkCallback)
Unregisters callbacks about and possibly releases networks originating from ConnectivityManager.RequestNetwork(NetworkRequest, .NetworkCallback) and ConnectivityManager.RegisterNetworkCallback(NetworkRequest,PendingIntent) calls.

Public Events