ConnectivityManager.RequestNetwork Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Handler, Int32) | |
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Int32) | |
RequestNetwork(NetworkRequest, PendingIntent) |
Request a network to satisfy a set of |
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback) |
Request a network to satisfy a set of NetworkCapabilities. |
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Handler) |
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Handler, Int32)
[Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;Landroid/os/Handler;I)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Landroid_os_Handler_IHandler", ApiSince=26)]
public virtual void RequestNetwork (Android.Net.NetworkRequest request, Android.Net.ConnectivityManager.NetworkCallback networkCallback, Android.OS.Handler handler, int timeoutMs);
[<Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;Landroid/os/Handler;I)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Landroid_os_Handler_IHandler", ApiSince=26)>]
abstract member RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * Android.OS.Handler * int -> unit
override this.RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * Android.OS.Handler * int -> unit
Parameters
- request
- NetworkRequest
- networkCallback
- ConnectivityManager.NetworkCallback
- handler
- Handler
- timeoutMs
- Int32
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Int32)
[Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;I)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_IHandler", ApiSince=26)]
public virtual void RequestNetwork (Android.Net.NetworkRequest request, Android.Net.ConnectivityManager.NetworkCallback networkCallback, int timeoutMs);
[<Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;I)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_IHandler", ApiSince=26)>]
abstract member RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * int -> unit
override this.RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * int -> unit
Parameters
- request
- NetworkRequest
- networkCallback
- ConnectivityManager.NetworkCallback
- timeoutMs
- Int32
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
RequestNetwork(NetworkRequest, PendingIntent)
Request a network to satisfy a set of NetworkCapabilities
.
[Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/app/PendingIntent;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_app_PendingIntent_Handler", ApiSince=22)]
public virtual void RequestNetwork (Android.Net.NetworkRequest request, Android.App.PendingIntent operation);
[<Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/app/PendingIntent;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_app_PendingIntent_Handler", ApiSince=22)>]
abstract member RequestNetwork : Android.Net.NetworkRequest * Android.App.PendingIntent -> unit
override this.RequestNetwork : Android.Net.NetworkRequest * Android.App.PendingIntent -> unit
Parameters
- request
- NetworkRequest
NetworkRequest
describing this request.
- operation
- PendingIntent
Action to perform when the network is available (corresponds
to the NetworkCallback#onAvailable
call. Typically
comes from PendingIntent#getBroadcast
. Cannot be null.
- Attributes
Remarks
Request a network to satisfy a set of NetworkCapabilities
.
This function behaves identically to the version that takes a NetworkCallback, but instead of NetworkCallback
a PendingIntent
is used. This means the request may outlive the calling application and get called back when a suitable network is found.
The operation is an Intent broadcast that goes to a broadcast receiver that you registered with Context#registerReceiver
or through the <receiver> tag in an AndroidManifest.xml file
The operation Intent is delivered with two extras, a Network
typed extra called #EXTRA_NETWORK
and a NetworkRequest
typed extra called #EXTRA_NETWORK_REQUEST
containing the original requests parameters. It is important to create a new, NetworkCallback
based request before completing the processing of the Intent to reserve the network or it will be released shortly after the Intent is processed.
If there is already a request for this Intent registered (with the equality of two Intents defined by Intent#filterEquals
), then it will be removed and replaced by this one, effectively releasing the previous NetworkRequest
.
The request may be released normally by calling #releaseNetworkRequest(android.app.PendingIntent)
.
It is presently unsupported to request a network with either NetworkCapabilities#NET_CAPABILITY_VALIDATED
or NetworkCapabilities#NET_CAPABILITY_CAPTIVE_PORTAL
as these NetworkCapabilities
represent states that a particular network may never attain, and whether a network will attain these states is unknown prior to bringing up the network so the framework does not know how to go about satisfying a request with these capabilities.
To avoid performance issues due to apps leaking callbacks, the system will limit the number of outstanding requests to 100 per app (identified by their UID), shared with all variants of this method, of #registerNetworkCallback
as well as ConnectivityDiagnosticsManager#registerConnectivityDiagnosticsCallback
. Requesting a network with this method will count toward this limit. If this limit is exceeded, an exception will be thrown. To avoid hitting this issue and to conserve resources, make sure to unregister the callbacks with #unregisterNetworkCallback(PendingIntent)
or #releaseNetworkRequest(PendingIntent)
.
This method requires the caller to hold either the android.Manifest.permission#CHANGE_NETWORK_STATE
permission or the ability to modify system settings as determined by android.provider.Settings.System#canWrite
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback)
Request a network to satisfy a set of NetworkCapabilities.
[Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Handler")]
public virtual void RequestNetwork (Android.Net.NetworkRequest request, Android.Net.ConnectivityManager.NetworkCallback networkCallback);
[<Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Handler")>]
abstract member RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback -> unit
override this.RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback -> unit
Parameters
- request
- NetworkRequest
NetworkRequest describing this request.
- networkCallback
- ConnectivityManager.NetworkCallback
The ConnectivityManager.NetworkCallback to be utilized for this request. Note the callback must not be shared - they uniquely specify this request.
- Attributes
Exceptions
if request
specifies any mutable
NetworkCapabilities
.
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
RequestNetwork(NetworkRequest, ConnectivityManager+NetworkCallback, Handler)
[Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;Landroid/os/Handler;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Landroid_os_Handler_Handler", ApiSince=26)]
public virtual void RequestNetwork (Android.Net.NetworkRequest request, Android.Net.ConnectivityManager.NetworkCallback networkCallback, Android.OS.Handler handler);
[<Android.Runtime.Register("requestNetwork", "(Landroid/net/NetworkRequest;Landroid/net/ConnectivityManager$NetworkCallback;Landroid/os/Handler;)V", "GetRequestNetwork_Landroid_net_NetworkRequest_Landroid_net_ConnectivityManager_NetworkCallback_Landroid_os_Handler_Handler", ApiSince=26)>]
abstract member RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * Android.OS.Handler -> unit
override this.RequestNetwork : Android.Net.NetworkRequest * Android.Net.ConnectivityManager.NetworkCallback * Android.OS.Handler -> unit
Parameters
- request
- NetworkRequest
- networkCallback
- ConnectivityManager.NetworkCallback
- handler
- Handler
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.