Share via


VpnService.SetUnderlyingNetworks(Network[]) Method

Definition

Sets the underlying networks used by the VPN for its upstream connections.

[Android.Runtime.Register("setUnderlyingNetworks", "([Landroid/net/Network;)Z", "GetSetUnderlyingNetworks_arrayLandroid_net_Network_Handler", ApiSince=22)]
public virtual bool SetUnderlyingNetworks (Android.Net.Network[]? networks);
[<Android.Runtime.Register("setUnderlyingNetworks", "([Landroid/net/Network;)Z", "GetSetUnderlyingNetworks_arrayLandroid_net_Network_Handler", ApiSince=22)>]
abstract member SetUnderlyingNetworks : Android.Net.Network[] -> bool
override this.SetUnderlyingNetworks : Android.Net.Network[] -> bool

Parameters

networks
Network[]

An array of networks the VPN uses to tunnel traffic to/from its servers.

Returns

true on success.

Attributes

Remarks

Sets the underlying networks used by the VPN for its upstream connections.

Used by the system to know the actual networks that carry traffic for apps affected by this VPN in order to present this information to the user (e.g., via status bar icons).

This method only needs to be called if the VPN has explicitly bound its underlying communications channels &mdash; such as the socket(s) passed to #protect(int) &mdash; to a Network using APIs such as Network#bindSocket(Socket) or Network#bindSocket(DatagramSocket). The VPN should call this method every time the set of Networks it is using changes.

networks is one of the following: <ul> <li><strong>a non-empty array</strong>: an array of one or more Networks, in decreasing preference order. For example, if this VPN uses both wifi and mobile (cellular) networks to carry app traffic, but prefers or uses wifi more than mobile, wifi should appear first in the array.</li> <li><strong>an empty array</strong>: a zero-element array, meaning that the VPN has no underlying network connection, and thus, app traffic will not be sent or received.</li> <li><strong>null</strong>: (default) signifies that the VPN uses whatever is the system's default network. I.e., it doesn't use the bindSocket or bindDatagramSocket APIs mentioned above to send traffic over specific channels.</li> </ul>

This call will succeed only if the VPN is currently established. For setting this value when the VPN has not yet been established, see Builder#setUnderlyingNetworks.

Java documentation for android.net.VpnService.setUnderlyingNetworks(android.net.Network[]).

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