BluetoothAdapter.Enable Method

Definition

Turn on the local Bluetooth adapter—do not use without explicit user action to turn on Bluetooth.

[Android.Runtime.Register("enable", "()Z", "")]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public bool Enable ();
[<Android.Runtime.Register("enable", "()Z", "")>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.Enable : unit -> bool

Returns

true to indicate adapter startup has begun, or false on immediate error

Attributes

Remarks

Turn on the local Bluetooth adapter&mdash;do not use without explicit user action to turn on Bluetooth.

This powers on the underlying Bluetooth hardware, and starts all Bluetooth system services.

<strong>Bluetooth should never be enabled without direct user consent</strong>. If you want to turn on Bluetooth in order to create a wireless connection, you should use the #ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The #enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

This is an asynchronous call: it will return immediately, and clients should listen for #ACTION_STATE_CHANGED to be notified of subsequent adapter state changes. If this call returns true, then the adapter state will immediately transition from #STATE_OFF to #STATE_TURNING_ON, and some time later transition to either #STATE_OFF or #STATE_ON. If this call returns false then there was an immediate problem that will prevent the adapter from being turned on - such as Airplane mode, or the adapter is already turned on.

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

Java documentation for android.bluetooth.BluetoothAdapter.enable().

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