Freigeben über


WifiManager.EnableNetwork(Int32, Boolean) Method

Definition

Allow a previously configured network to be associated with.

[Android.Runtime.Register("enableNetwork", "(IZ)Z", "GetEnableNetwork_IZHandler")]
public virtual bool EnableNetwork (int netId, bool attemptConnect);
[<Android.Runtime.Register("enableNetwork", "(IZ)Z", "GetEnableNetwork_IZHandler")>]
abstract member EnableNetwork : int * bool -> bool
override this.EnableNetwork : int * bool -> bool

Parameters

netId
Int32

the ID of the network as returned by #addNetwork or #getConfiguredNetworks.

attemptConnect
Boolean

The way to select a particular network to connect to is specify true for this parameter.

Returns

true if the operation succeeded

Attributes

Remarks

Allow a previously configured network to be associated with. If attemptConnect is true, an attempt to connect to the selected network is initiated. This may result in the asynchronous delivery of state change events.

<b>Note:</b> Network communication may not use Wi-Fi even if Wi-Fi is connected; traffic may instead be sent through another network, such as cellular data, Bluetooth tethering, or Ethernet. For example, traffic will never use a Wi-Fi network that does not provide Internet access (e.g. a wireless printer), if another network that does offer Internet access (e.g. cellular data) is available. Applications that need to ensure that their network traffic uses Wi-Fi should use APIs such as Network#bindSocket(java.net.Socket), Network#openConnection(java.net.URL), or ConnectivityManager#bindProcessToNetwork to do so.

Applications are not allowed to enable networks created by other applications.

This member is deprecated. a) See WifiNetworkSpecifier.Builder#build() for new mechanism to trigger connection to a Wi-Fi network. b) See #addNetworkSuggestions(List), #removeNetworkSuggestions(List) for new API to add Wi-Fi networks for consideration when auto-connecting to wifi. <b>Compatibility Note:</b> For applications targeting android.os.Build.VERSION_CODES#Q or above, this API will always fail and return false. Deprecation Exemptions: <ul> <li>Device Owner (DO), Profile Owner (PO) and system apps. </ul>

Java documentation for android.net.wifi.WifiManager.enableNetwork(int, boolean).

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