Compartilhar via


WifiManager.SetWifiEnabled(Boolean) Method

Definition

Enable or disable Wi-Fi.

[Android.Runtime.Register("setWifiEnabled", "(Z)Z", "GetSetWifiEnabled_ZHandler")]
public virtual bool SetWifiEnabled (bool enabled);
[<Android.Runtime.Register("setWifiEnabled", "(Z)Z", "GetSetWifiEnabled_ZHandler")>]
abstract member SetWifiEnabled : bool -> bool
override this.SetWifiEnabled : bool -> bool

Parameters

enabled
Boolean

true to enable, false to disable.

Returns

false if the request cannot be satisfied; true indicates that wifi is either already in the requested state, or in progress toward the requested state.

Attributes

Remarks

Enable or disable Wi-Fi.

Applications must have the android.Manifest.permission#CHANGE_WIFI_STATE permission to toggle wifi.

This member is deprecated. Starting with Build.VERSION_CODES#Q, applications are not allowed to enable/disable Wi-Fi. <b>Compatibility Note:</b> For applications targeting android.os.Build.VERSION_CODES#Q or above, this API will always fail and return false. If apps are targeting an older SDK (android.os.Build.VERSION_CODES#P or below), they can continue to use this API. <p> Deprecation Exemptions: <ul> <li>Device Owner (DO), Profile Owner (PO) and system apps. </ul>

Starting with android.os.Build.VERSION_CODES#TIRAMISU, DO/COPE may set a user restriction (DISALLOW_CHANGE_WIFI_STATE) to only allow DO/PO to use this API.

Java documentation for android.net.wifi.WifiManager.setWifiEnabled(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