Added in API level 5

BluetoothAdapter


class BluetoothAdapter
kotlin.Any
   ↳ android.bluetooth.BluetoothAdapter

Represents the local device Bluetooth adapter. The BluetoothAdapter lets you perform fundamental Bluetooth tasks, such as initiate device discovery, query a list of bonded (paired) devices, instantiate a BluetoothDevice using a known MAC address, and create a BluetoothServerSocket to listen for connection requests from other devices, and start a scan for Bluetooth LE devices.

To get a BluetoothAdapter representing the local Bluetooth adapter, call the android.bluetooth.BluetoothManager#getAdapter function on BluetoothManager. On JELLY_BEAN_MR1 and below you will need to use the static getDefaultAdapter method instead.

Fundamentally, this is your starting point for all Bluetooth actions. Once you have the local adapter, you can get a set of BluetoothDevice objects representing all paired devices with getBondedDevices(); start device discovery with startDiscovery(); or create a BluetoothServerSocket to listen for incoming RFComm connection requests with listenUsingRfcommWithServiceRecord(java.lang.String,java.util.UUID); listen for incoming L2CAP Connection-oriented Channels (CoC) connection requests with listenUsingL2capChannel(); or start a scan for Bluetooth LE devices with BluetoothLeScanner.startScan(ScanCallback) using the scanner from getBluetoothLeScanner().

This class is thread safe.

Summary

Nested classes
abstract

Callback interface used to deliver LE scan results.

Constants
static String

Intent used to broadcast the change in connection state of the local Bluetooth adapter to a profile of the remote device.

static String

Broadcast Action: The local Bluetooth adapter has finished the device discovery process.

static String

Broadcast Action: The local Bluetooth adapter has started the remote device discovery process.

static String

Broadcast Action: The local Bluetooth adapter has changed its friendly Bluetooth name.

static String

Activity Action: Show a system activity that requests discoverable mode.

static String

Activity Action: Show a system activity that allows the user to turn on Bluetooth.

static String

Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter has changed.

static String

Broadcast Action: The state of the local Bluetooth adapter has been changed.

static Int

Sentinel error value for this class.

static String

Extra used by ACTION_CONNECTION_STATE_CHANGED

static String

Used as an optional int extra field in ACTION_REQUEST_DISCOVERABLE intents to request a specific duration for discoverability in seconds.

static String

Used as a String extra field in ACTION_LOCAL_NAME_CHANGED intents to request the local Bluetooth name.

static String

Extra used by ACTION_CONNECTION_STATE_CHANGED

static String

Used as an int extra field in ACTION_SCAN_MODE_CHANGED intents to request the previous scan mode.

static String

Used as an int extra field in ACTION_STATE_CHANGED intents to request the previous power state.

static String

Used as an int extra field in ACTION_SCAN_MODE_CHANGED intents to request the current scan mode.

static String

Used as an int extra field in ACTION_STATE_CHANGED intents to request the current power state.

static Int

Indicates that inquiry scan is disabled, but page scan is enabled on the local Bluetooth adapter.

static Int

Indicates that both inquiry scan and page scan are enabled on the local Bluetooth adapter.

static Int

Indicates that both inquiry scan and page scan are disabled on the local Bluetooth adapter.

static Int

The profile is in connected state

static Int

The profile is in connecting state

static Int

The profile is in disconnected state

static Int

The profile is in disconnecting state

static Int

Indicates the local Bluetooth adapter is off.

static Int

Indicates the local Bluetooth adapter is on, and ready for use.

static Int

Indicates the local Bluetooth adapter is turning off.

static Int

Indicates the local Bluetooth adapter is turning on.

Public methods
Boolean

Cancel the current device discovery process.

static Boolean

Validate a String Bluetooth address, such as "00:43:A8:23:10:F0"

Unit
closeProfileProxy(unusedProfile: Int, proxy: BluetoothProfile!)

Close the connection of the profile proxy to the Service.

Boolean

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

Boolean

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

String!

Returns the hardware address of the local Bluetooth adapter.

BluetoothLeAdvertiser!

Returns a BluetoothLeAdvertiser object for Bluetooth LE Advertising operations.

BluetoothLeScanner!

Returns a BluetoothLeScanner object for Bluetooth LE scan operations.

MutableSet<BluetoothDevice!>!

Return the set of BluetoothDevice objects that are bonded (paired) to the local adapter.

static BluetoothAdapter!

Get a handle to the default local Bluetooth adapter.

Duration?

Get the timeout duration of the SCAN_MODE_CONNECTABLE_DISCOVERABLE.

Int

Return the maximum LE advertising data length in bytes, if LE Extended Advertising feature is supported, 0 otherwise.

Int

Get the maximum number of connected devices per audio profile for this device.

String!

Get the friendly Bluetooth name of the local Bluetooth adapter.

Int

Get the current connection state of a profile.

Boolean
getProfileProxy(context: Context!, listener: BluetoothProfile.ServiceListener!, profile: Int)

Get the profile proxy object associated with the profile.

BluetoothDevice!

Get a BluetoothDevice object for the given Bluetooth hardware address.

BluetoothDevice!

Get a BluetoothDevice object for the given Bluetooth hardware address.

BluetoothDevice
getRemoteLeDevice(address: String, addressType: Int)

Get a BluetoothDevice object for the given Bluetooth hardware address and addressType.

Int

Get the current Bluetooth scan mode of the local Bluetooth adapter.

Int

Get the current state of the local Bluetooth adapter.

Boolean

Return true if the local Bluetooth adapter is currently in the device discovery process.

Boolean

Return true if Bluetooth is currently enabled and ready for use.

Boolean

Return true if LE 2M PHY feature is supported.

Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio broadcast assistant feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio broadcast source feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Boolean

Return true if LE Coded PHY feature is supported.

Boolean

Return true if LE Extended Advertising feature is supported.

Boolean

Return true if LE Periodic Advertising feature is supported.

Boolean

Return true if the multi advertisement is supported by the chipset
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Boolean

Return true if offloaded filters are supported
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Boolean

Return true if offloaded scan batching is supported
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

BluetoothServerSocket

Create an insecure L2CAP Connection-oriented Channel (CoC) BluetoothServerSocket and assign a dynamic PSM value.

BluetoothServerSocket!

Create a listening, insecure RFCOMM Bluetooth socket with Service Record.

BluetoothServerSocket

Create a secure L2CAP Connection-oriented Channel (CoC) BluetoothServerSocket and assign a dynamic protocol/service multiplexer (PSM) value.

BluetoothServerSocket!

Create a listening, secure RFCOMM Bluetooth socket with Service Record.

Boolean
setName(name: String!)

Set the friendly Bluetooth name of the local Bluetooth adapter.

Boolean

Start the remote device discovery process.

Boolean

Starts a scan for Bluetooth LE devices.

Boolean
startLeScan(serviceUuids: Array<UUID!>!, callback: BluetoothAdapter.LeScanCallback!)

Starts a scan for Bluetooth LE devices, looking for devices that advertise given services.

Unit

Stops an ongoing Bluetooth LE device scan.

Protected methods
Unit

Constants

ACTION_CONNECTION_STATE_CHANGED

Added in API level 11
static val ACTION_CONNECTION_STATE_CHANGED: String

Intent used to broadcast the change in connection state of the local Bluetooth adapter to a profile of the remote device. When the adapter is not connected to any profiles of any remote devices and it attempts a connection to a profile this intent will be sent. Once connected, this intent will not be sent for any more connection attempts to any profiles of any remote device. When the adapter disconnects from the last profile its connected to of any remote device, this intent will be sent.

This intent is useful for applications that are only concerned about whether the local adapter is connected to any profile of any device and are not really concerned about which profile. For example, an application which displays an icon to display whether Bluetooth is connected or not can use this intent.

This intent will have 3 extras: EXTRA_CONNECTION_STATE - The current connection state. EXTRA_PREVIOUS_CONNECTION_STATE- The previous connection state. android.bluetooth.BluetoothDevice#EXTRA_DEVICE - The remote device.

EXTRA_CONNECTION_STATE or EXTRA_PREVIOUS_CONNECTION_STATE can be any of STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED"

ACTION_DISCOVERY_FINISHED

Added in API level 5
static val ACTION_DISCOVERY_FINISHED: String

Broadcast Action: The local Bluetooth adapter has finished the device discovery process.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Value: "android.bluetooth.adapter.action.DISCOVERY_FINISHED"

ACTION_DISCOVERY_STARTED

Added in API level 5
static val ACTION_DISCOVERY_STARTED: String

Broadcast Action: The local Bluetooth adapter has started the remote device discovery process.

This usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

Register for BluetoothDevice.ACTION_FOUND to be notified as remote Bluetooth devices are found.

Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Value: "android.bluetooth.adapter.action.DISCOVERY_STARTED"

ACTION_LOCAL_NAME_CHANGED

Added in API level 5
static val ACTION_LOCAL_NAME_CHANGED: String

Broadcast Action: The local Bluetooth adapter has changed its friendly Bluetooth name.

This name is visible to remote Bluetooth devices.

Always contains the extra field EXTRA_LOCAL_NAME containing the name.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.adapter.action.LOCAL_NAME_CHANGED"

ACTION_REQUEST_DISCOVERABLE

Added in API level 5
static val ACTION_REQUEST_DISCOVERABLE: String

Activity Action: Show a system activity that requests discoverable mode. This activity will also request the user to turn on Bluetooth if it is not currently enabled.

Discoverable mode is equivalent to SCAN_MODE_CONNECTABLE_DISCOVERABLE. It allows remote devices to see this Bluetooth adapter when they perform a discovery.

For privacy, Android is not discoverable by default.

The sender of this Intent can optionally use extra field EXTRA_DISCOVERABLE_DURATION to request the duration of discoverability. Currently the default duration is 120 seconds, and maximum duration is capped at 300 seconds for each request.

Notification of the result of this activity is posted using the android.app.Activity#onActivityResult callback. The resultCode will be the duration (in seconds) of discoverability or android.app.Activity#RESULT_CANCELED if the user rejected discoverability or an error has occurred.

Applications can also listen for ACTION_SCAN_MODE_CHANGED for global notification whenever the scan mode changes. For example, an application can be notified when the device has ended discoverability.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_ADVERTISE permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_ADVERTISE

Value: "android.bluetooth.adapter.action.REQUEST_DISCOVERABLE"

ACTION_REQUEST_ENABLE

Added in API level 5
static val ACTION_REQUEST_ENABLE: String

Activity Action: Show a system activity that allows the user to turn on Bluetooth.

This system activity will return once Bluetooth has completed turning on, or the user has decided not to turn Bluetooth on.

Notification of the result of this activity is posted using the android.app.Activity#onActivityResult callback. The resultCode will be android.app.Activity#RESULT_OK if Bluetooth has been turned on or android.app.Activity#RESULT_CANCELED if the user has rejected the request or an error has occurred.

Applications can also listen for ACTION_STATE_CHANGED for global notification whenever Bluetooth is turned on or off.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Value: "android.bluetooth.adapter.action.REQUEST_ENABLE"

ACTION_SCAN_MODE_CHANGED

Added in API level 5
static val ACTION_SCAN_MODE_CHANGED: String

Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter has changed.

Always contains the extra fields EXTRA_SCAN_MODE and EXTRA_PREVIOUS_SCAN_MODE containing the new and old scan modes respectively.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Value: "android.bluetooth.adapter.action.SCAN_MODE_CHANGED"

ACTION_STATE_CHANGED

Added in API level 5
static val ACTION_STATE_CHANGED: String

Broadcast Action: The state of the local Bluetooth adapter has been changed.

For example, Bluetooth has been turned on or off.

Always contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE containing the new and old states respectively.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Value: "android.bluetooth.adapter.action.STATE_CHANGED"

ERROR

Added in API level 5
static val ERROR: Int

Sentinel error value for this class. Guaranteed to not equal any other integer constant in this class. Provided as a convenience for functions that require a sentinel error value, for example:

Intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)

Value: -2147483648

EXTRA_CONNECTION_STATE

Added in API level 11
static val EXTRA_CONNECTION_STATE: String

Extra used by ACTION_CONNECTION_STATE_CHANGED

This extra represents the current connection state.

Value: "android.bluetooth.adapter.extra.CONNECTION_STATE"

EXTRA_DISCOVERABLE_DURATION

Added in API level 5
static val EXTRA_DISCOVERABLE_DURATION: String

Used as an optional int extra field in ACTION_REQUEST_DISCOVERABLE intents to request a specific duration for discoverability in seconds. The current default is 120 seconds, and requests over 300 seconds will be capped. These values could change.

Value: "android.bluetooth.adapter.extra.DISCOVERABLE_DURATION"

EXTRA_LOCAL_NAME

Added in API level 5
static val EXTRA_LOCAL_NAME: String

Used as a String extra field in ACTION_LOCAL_NAME_CHANGED intents to request the local Bluetooth name.

Value: "android.bluetooth.adapter.extra.LOCAL_NAME"

EXTRA_PREVIOUS_CONNECTION_STATE

Added in API level 11
static val EXTRA_PREVIOUS_CONNECTION_STATE: String

Extra used by ACTION_CONNECTION_STATE_CHANGED

This extra represents the previous connection state.

Value: "android.bluetooth.adapter.extra.PREVIOUS_CONNECTION_STATE"

EXTRA_PREVIOUS_SCAN_MODE

Added in API level 5
static val EXTRA_PREVIOUS_SCAN_MODE: String

Used as an int extra field in ACTION_SCAN_MODE_CHANGED intents to request the previous scan mode. Possible values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE,

Value: "android.bluetooth.adapter.extra.PREVIOUS_SCAN_MODE"

EXTRA_PREVIOUS_STATE

Added in API level 5
static val EXTRA_PREVIOUS_STATE: String

Used as an int extra field in ACTION_STATE_CHANGED intents to request the previous power state. Possible values are: STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF

Value: "android.bluetooth.adapter.extra.PREVIOUS_STATE"

EXTRA_SCAN_MODE

Added in API level 5
static val EXTRA_SCAN_MODE: String

Used as an int extra field in ACTION_SCAN_MODE_CHANGED intents to request the current scan mode. Possible values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE,

Value: "android.bluetooth.adapter.extra.SCAN_MODE"

EXTRA_STATE

Added in API level 5
static val EXTRA_STATE: String

Used as an int extra field in ACTION_STATE_CHANGED intents to request the current power state. Possible values are: STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF,

Value: "android.bluetooth.adapter.extra.STATE"

SCAN_MODE_CONNECTABLE

Added in API level 5
static val SCAN_MODE_CONNECTABLE: Int

Indicates that inquiry scan is disabled, but page scan is enabled on the local Bluetooth adapter. Therefore this device is not discoverable from remote Bluetooth devices, but is connectable from remote devices that have previously discovered this device.

Value: 21

SCAN_MODE_CONNECTABLE_DISCOVERABLE

Added in API level 5
static val SCAN_MODE_CONNECTABLE_DISCOVERABLE: Int

Indicates that both inquiry scan and page scan are enabled on the local Bluetooth adapter. Therefore this device is both discoverable and connectable from remote Bluetooth devices.

Value: 23

SCAN_MODE_NONE

Added in API level 5
static val SCAN_MODE_NONE: Int

Indicates that both inquiry scan and page scan are disabled on the local Bluetooth adapter. Therefore this device is neither discoverable nor connectable from remote Bluetooth devices.

Value: 20

STATE_CONNECTED

Added in API level 11
static val STATE_CONNECTED: Int

The profile is in connected state

Value: 2

STATE_CONNECTING

Added in API level 11
static val STATE_CONNECTING: Int

The profile is in connecting state

Value: 1

STATE_DISCONNECTED

Added in API level 11
static val STATE_DISCONNECTED: Int

The profile is in disconnected state

Value: 0

STATE_DISCONNECTING

Added in API level 11
static val STATE_DISCONNECTING: Int

The profile is in disconnecting state

Value: 3

STATE_OFF

Added in API level 5
static val STATE_OFF: Int

Indicates the local Bluetooth adapter is off.

Value: 10

STATE_ON

Added in API level 5
static val STATE_ON: Int

Indicates the local Bluetooth adapter is on, and ready for use.

Value: 12

STATE_TURNING_OFF

Added in API level 5
static val STATE_TURNING_OFF: Int

Indicates the local Bluetooth adapter is turning off. Local clients should immediately attempt graceful disconnection of any remote links.

Value: 13

STATE_TURNING_ON

Added in API level 5
static val STATE_TURNING_ON: Int

Indicates the local Bluetooth adapter is turning on. However local clients should wait for STATE_ON before attempting to use the adapter.

Value: 11

Public methods

cancelDiscovery

Added in API level 5
fun cancelDiscovery(): Boolean

Cancel the current device discovery process.

Because discovery is a heavyweight procedure for the Bluetooth adapter, this method should always be called before attempting to connect to a remote device with android.bluetooth.BluetoothSocket#connect(). Discovery is not managed by the Activity, but is run as a system service, so an application should always call cancel discovery even if it did not directly request a discovery, just to be sure.

If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Return
Boolean true on success, false on error

checkBluetoothAddress

Added in API level 5
static fun checkBluetoothAddress(address: String!): Boolean

Validate a String Bluetooth address, such as "00:43:A8:23:10:F0"

Alphabetic characters must be uppercase to be valid.

Parameters
address String!: Bluetooth address as string
Return
Boolean true if the address is valid, false otherwise

closeProfileProxy

Added in API level 11
fun closeProfileProxy(
    unusedProfile: Int,
    proxy: BluetoothProfile!
): Unit

Close the connection of the profile proxy to the Service.

Clients should call this when they are no longer using the proxy obtained from getProfileProxy. Profile can be one of BluetoothProfile.HEADSET or android.bluetooth.BluetoothProfile#A2DP

Parameters
proxy BluetoothProfile!: Profile proxy object

disable

Added in API level 5
Deprecated in API level 33
fun disable(): Boolean

Deprecated: Starting with android.os.Build.VERSION_CODES#TIRAMISU, applications are not allowed to enable/disable Bluetooth. Compatibility Note: 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.

Deprecation Exemptions:

  • Device Owner (DO), Profile Owner (PO) and system apps.

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

This gracefully shuts down all Bluetooth connections, stops Bluetooth system services, and powers down the underlying Bluetooth hardware.

Bluetooth should never be disabled without direct user consent. The disable() 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_ON to STATE_TURNING_OFF, 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 off - such as the adapter already being turned off.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Boolean true to indicate adapter shutdown has begun, or false on immediate error

enable

Added in API level 5
Deprecated in API level 33
fun enable(): Boolean

Deprecated: Starting with android.os.Build.VERSION_CODES#TIRAMISU, applications are not allowed to enable/disable Bluetooth. Compatibility Note: 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.

Deprecation Exemptions:

  • Device Owner (DO), Profile Owner (PO) and system apps.

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

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

Bluetooth should never be enabled without direct user consent. 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.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

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

getAddress

Added in API level 5
fun getAddress(): String!

Returns the hardware address of the local Bluetooth adapter.

For example, "00:11:22:AA:BB:CC".
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT and android.Manifest.permission#LOCAL_MAC_ADDRESS

Return
String! Bluetooth hardware address as string

getBluetoothLeAdvertiser

Added in API level 21
fun getBluetoothLeAdvertiser(): BluetoothLeAdvertiser!

Returns a BluetoothLeAdvertiser object for Bluetooth LE Advertising operations. Will return null if Bluetooth is turned off or if Bluetooth LE Advertising is not supported on this device.

Use isMultipleAdvertisementSupported() to check whether LE Advertising is supported on this device before calling this method.

getBluetoothLeScanner

Added in API level 21
fun getBluetoothLeScanner(): BluetoothLeScanner!

Returns a BluetoothLeScanner object for Bluetooth LE scan operations.

getBondedDevices

Added in API level 5
fun getBondedDevices(): MutableSet<BluetoothDevice!>!

Return the set of BluetoothDevice objects that are bonded (paired) to the local adapter.

If Bluetooth state is not STATE_ON, this API will return an empty set. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
MutableSet<BluetoothDevice!>! unmodifiable set of BluetoothDevice, or null on error

getDefaultAdapter

Added in API level 5
Deprecated in API level 31
static fun getDefaultAdapter(): BluetoothAdapter!

Deprecated: this method will continue to work, but developers are strongly encouraged to migrate to using BluetoothManager.getAdapter(), since that approach enables support for Context.createAttributionContext.

Get a handle to the default local Bluetooth adapter.

Currently Android only supports one Bluetooth adapter, but the API could be extended to support more. This will always return the default adapter.

Return
BluetoothAdapter! the default local adapter, or null if Bluetooth is not supported on this hardware platform

getDiscoverableTimeout

Added in API level 33
fun getDiscoverableTimeout(): Duration?

Get the timeout duration of the SCAN_MODE_CONNECTABLE_DISCOVERABLE.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Return
Duration? the duration of the discoverable timeout or null if an error has occurred

getLeMaximumAdvertisingDataLength

Added in API level 26
fun getLeMaximumAdvertisingDataLength(): Int

Return the maximum LE advertising data length in bytes, if LE Extended Advertising feature is supported, 0 otherwise.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Int the maximum LE advertising data length.

getMaxConnectedAudioDevices

Added in API level 33
fun getMaxConnectedAudioDevices(): Int

Get the maximum number of connected devices per audio profile for this device.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Int the number of allowed simultaneous connected devices for each audio profile for this device, or -1 if the Bluetooth service can't be reached

getName

Added in API level 5
fun getName(): String!

Get the friendly Bluetooth name of the local Bluetooth adapter.

This name is visible to remote Bluetooth devices.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
String! the Bluetooth name, or null on error

getProfileConnectionState

Added in API level 14
fun getProfileConnectionState(profile: Int): Int

Get the current connection state of a profile. This function can be used to check whether the local Bluetooth adapter is connected to any remote device for a specific profile. Profile can be one of BluetoothProfile.HEADSET, BluetoothProfile.A2DP.

Return the profile connection state
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
Int Value is android.bluetooth.BluetoothAdapter#STATE_DISCONNECTED, android.bluetooth.BluetoothAdapter#STATE_CONNECTING, android.bluetooth.BluetoothAdapter#STATE_CONNECTED, or android.bluetooth.BluetoothAdapter#STATE_DISCONNECTING

getProfileProxy

Added in API level 11
fun getProfileProxy(
    context: Context!,
    listener: BluetoothProfile.ServiceListener!,
    profile: Int
): Boolean

Get the profile proxy object associated with the profile.

The ServiceListener's methods will be invoked on the application's main looper

Parameters
context Context!: Context of the application
listener BluetoothProfile.ServiceListener!: The service listener for connection callbacks.
profile Int: The Bluetooth profile to listen for status change
Return
Boolean true on success, false on error

getRemoteDevice

Added in API level 16
fun getRemoteDevice(address: ByteArray!): BluetoothDevice!

Get a BluetoothDevice object for the given Bluetooth hardware address.

Valid Bluetooth hardware addresses must be 6 bytes. This method expects the address in network byte order (MSB first).

A BluetoothDevice will always be returned for a valid hardware address, even if this adapter has never seen that device.

Parameters
address ByteArray!: Bluetooth MAC address (6 bytes)
Exceptions
java.lang.IllegalArgumentException if address is invalid

getRemoteDevice

Added in API level 5
fun getRemoteDevice(address: String!): BluetoothDevice!

Get a BluetoothDevice object for the given Bluetooth hardware address.

Valid Bluetooth hardware addresses must be upper case, in big endian byte order, and in a format such as "00:11:22:33:AA:BB". The helper checkBluetoothAddress is available to validate a Bluetooth address.

A BluetoothDevice will always be returned for a valid hardware address, even if this adapter has never seen that device.

Parameters
address String!: valid Bluetooth MAC address
Exceptions
java.lang.IllegalArgumentException if address is invalid

getRemoteLeDevice

Added in API level 33
fun getRemoteLeDevice(
    address: String,
    addressType: Int
): BluetoothDevice

Get a BluetoothDevice object for the given Bluetooth hardware address and addressType.

Valid Bluetooth hardware addresses must be upper case, in big endian byte order, and in a format such as "00:11:22:33:AA:BB". The helper checkBluetoothAddress is available to validate a Bluetooth address.

A BluetoothDevice will always be returned for a valid hardware address and type, even if this adapter has never seen that device.

Parameters
address String: valid Bluetooth MAC address This value cannot be null.
addressType Int: Bluetooth address type Value is android.bluetooth.BluetoothDevice#ADDRESS_TYPE_PUBLIC, android.bluetooth.BluetoothDevice#ADDRESS_TYPE_RANDOM, android.bluetooth.BluetoothDevice#ADDRESS_TYPE_ANONYMOUS, or android.bluetooth.BluetoothDevice#ADDRESS_TYPE_UNKNOWN
Return
BluetoothDevice This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if address is invalid

getScanMode

Added in API level 5
fun getScanMode(): Int

Get the current Bluetooth scan mode of the local Bluetooth adapter.

The Bluetooth scan mode determines if the local adapter is connectable and/or discoverable from remote Bluetooth devices.

Possible values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE.

If Bluetooth state is not STATE_ON, this API will return SCAN_MODE_NONE. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Return
Int scan mode Value is android.bluetooth.BluetoothAdapter#SCAN_MODE_NONE, android.bluetooth.BluetoothAdapter#SCAN_MODE_CONNECTABLE, or android.bluetooth.BluetoothAdapter#SCAN_MODE_CONNECTABLE_DISCOVERABLE

getState

Added in API level 5
fun getState(): Int

Get the current state of the local Bluetooth adapter.

Possible return values are STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Int current state of Bluetooth adapter Value is android.bluetooth.BluetoothAdapter#STATE_OFF, android.bluetooth.BluetoothAdapter#STATE_TURNING_ON, android.bluetooth.BluetoothAdapter#STATE_ON, or android.bluetooth.BluetoothAdapter#STATE_TURNING_OFF

isDiscovering

Added in API level 5
fun isDiscovering(): Boolean

Return true if the local Bluetooth adapter is currently in the device discovery process.

Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery.

Applications can also register for ACTION_DISCOVERY_STARTED or ACTION_DISCOVERY_FINISHED to be notified when discovery starts or completes.

If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Return
Boolean true if discovering

isEnabled

Added in API level 5
fun isEnabled(): Boolean

Return true if Bluetooth is currently enabled and ready for use.

Equivalent to: getBluetoothState() == STATE_ON
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if the local adapter is turned on

isLe2MPhySupported

Added in API level 26
fun isLe2MPhySupported(): Boolean

Return true if LE 2M PHY feature is supported.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports LE 2M PHY feature

isLeAudioBroadcastAssistantSupported

Added in API level 33
fun isLeAudioBroadcastAssistantSupported(): Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio broadcast assistant feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Return
Int whether the LE audio broadcast assistant is supported Value is android.bluetooth.BluetoothStatusCodes#FEATURE_SUPPORTED, android.bluetooth.BluetoothStatusCodes#ERROR_UNKNOWN, android.bluetooth.BluetoothStatusCodes#ERROR_BLUETOOTH_NOT_ENABLED, or android.bluetooth.BluetoothStatusCodes#FEATURE_NOT_SUPPORTED
Exceptions
java.lang.IllegalStateException if the bluetooth service is null

isLeAudioBroadcastSourceSupported

Added in API level 33
fun isLeAudioBroadcastSourceSupported(): Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio broadcast source feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Return
Int whether the LE audio broadcast source is supported Value is android.bluetooth.BluetoothStatusCodes#FEATURE_SUPPORTED, android.bluetooth.BluetoothStatusCodes#ERROR_UNKNOWN, android.bluetooth.BluetoothStatusCodes#ERROR_BLUETOOTH_NOT_ENABLED, or android.bluetooth.BluetoothStatusCodes#FEATURE_NOT_SUPPORTED
Exceptions
java.lang.IllegalStateException if the bluetooth service is null

isLeAudioSupported

Added in API level 33
fun isLeAudioSupported(): Int

Returns BluetoothStatusCodes.FEATURE_SUPPORTED if the LE audio feature is supported, BluetoothStatusCodes.FEATURE_NOT_SUPPORTED if the feature is not supported, or an error code.

Return
Int whether the LE audio is supported Value is android.bluetooth.BluetoothStatusCodes#FEATURE_SUPPORTED, android.bluetooth.BluetoothStatusCodes#ERROR_UNKNOWN, android.bluetooth.BluetoothStatusCodes#ERROR_BLUETOOTH_NOT_ENABLED, or android.bluetooth.BluetoothStatusCodes#FEATURE_NOT_SUPPORTED
Exceptions
java.lang.IllegalStateException if the bluetooth service is null

isLeCodedPhySupported

Added in API level 26
fun isLeCodedPhySupported(): Boolean

Return true if LE Coded PHY feature is supported.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports LE Coded PHY feature

isLeExtendedAdvertisingSupported

Added in API level 26
fun isLeExtendedAdvertisingSupported(): Boolean

Return true if LE Extended Advertising feature is supported.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports LE Extended Advertising feature

isLePeriodicAdvertisingSupported

Added in API level 26
fun isLePeriodicAdvertisingSupported(): Boolean

Return true if LE Periodic Advertising feature is supported.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports LE Periodic Advertising feature

isMultipleAdvertisementSupported

Added in API level 21
fun isMultipleAdvertisementSupported(): Boolean

Return true if the multi advertisement is supported by the chipset
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if Multiple Advertisement feature is supported

isOffloadedFilteringSupported

Added in API level 21
fun isOffloadedFilteringSupported(): Boolean

Return true if offloaded filters are supported
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports on-chip filtering

isOffloadedScanBatchingSupported

Added in API level 21
fun isOffloadedScanBatchingSupported(): Boolean

Return true if offloaded scan batching is supported
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Return
Boolean true if chipset supports on-chip scan batching

listenUsingInsecureL2capChannel

Added in API level 29
fun listenUsingInsecureL2capChannel(): BluetoothServerSocket

Create an insecure L2CAP Connection-oriented Channel (CoC) BluetoothServerSocket and assign a dynamic PSM value. This socket can be used to listen for incoming connections. The supported Bluetooth transport is LE only.

The link key is not required to be authenticated, i.e. the communication may be vulnerable to person-in-the-middle attacks. Use listenUsingL2capChannel, if an encrypted and authenticated communication channel is desired.

Use android.bluetooth.BluetoothServerSocket#accept to retrieve incoming connections from a listening BluetoothServerSocket.

The system will assign a dynamic protocol/service multiplexer (PSM) value. This PSM value can be read from the BluetoothServerSocket.getPsm() and this value will be released when this server socket is closed, Bluetooth is turned off, or the application exits unexpectedly.

The mechanism of disclosing the assigned dynamic PSM value to the initiating peer is defined and performed by the application.

Use BluetoothDevice.createInsecureL2capChannel(int) to connect to this server socket from another Android device that is given the PSM value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
BluetoothServerSocket an L2CAP CoC BluetoothServerSocket This value cannot be null.
Exceptions
java.io.IOException on error, for example Bluetooth not available or unable to start this CoC

listenUsingInsecureRfcommWithServiceRecord

Added in API level 10
fun listenUsingInsecureRfcommWithServiceRecord(
    name: String!,
    uuid: UUID!
): BluetoothServerSocket!

Create a listening, insecure RFCOMM Bluetooth socket with Service Record.

The link key is not required to be authenticated, i.e. the communication may be vulnerable to Person In the Middle attacks. For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandatory. For legacy devices (pre Bluetooth 2.1 devices) the link will not be encrypted. Use listenUsingRfcommWithServiceRecord, if an encrypted and authenticated communication channel is desired.

Use android.bluetooth.BluetoothServerSocket#accept to retrieve incoming connections from a listening BluetoothServerSocket.

The system will assign an unused RFCOMM channel to listen on.

The system will also register a Service Discovery Protocol (SDP) record with the local SDP server containing the specified UUID, service name, and auto-assigned channel. Remote Bluetooth devices can use the same UUID to query our SDP server and discover which channel to connect to. This SDP record will be removed when this socket is closed, or if this application closes unexpectedly.

Use BluetoothDevice.createInsecureRfcommSocketToServiceRecord to connect to this socket from another device using the same UUID.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
name String!: service name for SDP record
uuid UUID!: uuid for SDP record
Return
BluetoothServerSocket! a listening RFCOMM BluetoothServerSocket
Exceptions
java.io.IOException on error, for example Bluetooth not available, or insufficient permissions, or channel in use.

listenUsingL2capChannel

Added in API level 29
fun listenUsingL2capChannel(): BluetoothServerSocket

Create a secure L2CAP Connection-oriented Channel (CoC) BluetoothServerSocket and assign a dynamic protocol/service multiplexer (PSM) value. This socket can be used to listen for incoming connections. The supported Bluetooth transport is LE only.

A remote device connecting to this socket will be authenticated and communication on this socket will be encrypted.

Use android.bluetooth.BluetoothServerSocket#accept to retrieve incoming connections from a listening BluetoothServerSocket.

The system will assign a dynamic PSM value. This PSM value can be read from the android.bluetooth.BluetoothServerSocket#getPsm() and this value will be released when this server socket is closed, Bluetooth is turned off, or the application exits unexpectedly.

The mechanism of disclosing the assigned dynamic PSM value to the initiating peer is defined and performed by the application.

Use BluetoothDevice.createL2capChannel(int) to connect to this server socket from another Android device that is given the PSM value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Return
BluetoothServerSocket an L2CAP CoC BluetoothServerSocket This value cannot be null.
Exceptions
java.io.IOException on error, for example Bluetooth not available or unable to start this CoC

listenUsingRfcommWithServiceRecord

Added in API level 5
fun listenUsingRfcommWithServiceRecord(
    name: String!,
    uuid: UUID!
): BluetoothServerSocket!

Create a listening, secure RFCOMM Bluetooth socket with Service Record.

A remote device connecting to this socket will be authenticated and communication on this socket will be encrypted.

Use android.bluetooth.BluetoothServerSocket#accept to retrieve incoming connections from a listening BluetoothServerSocket.

The system will assign an unused RFCOMM channel to listen on.

The system will also register a Service Discovery Protocol (SDP) record with the local SDP server containing the specified UUID, service name, and auto-assigned channel. Remote Bluetooth devices can use the same UUID to query our SDP server and discover which channel to connect to. This SDP record will be removed when this socket is closed, or if this application closes unexpectedly.

Use BluetoothDevice.createRfcommSocketToServiceRecord to connect to this socket from another device using the same UUID.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
name String!: service name for SDP record
uuid UUID!: uuid for SDP record
Return
BluetoothServerSocket! a listening RFCOMM BluetoothServerSocket
Exceptions
java.io.IOException on error, for example Bluetooth not available, or insufficient permissions, or channel in use.

setName

Added in API level 5
fun setName(name: String!): Boolean

Set the friendly Bluetooth name of the local Bluetooth adapter.

This name is visible to remote Bluetooth devices.

Valid Bluetooth names are a maximum of 248 bytes using UTF-8 encoding, although many remote devices can only display the first 40 characters, and some may be limited to just 20.

If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_CONNECT

Parameters
name String!: a valid Bluetooth name
Return
Boolean true if the name was set, false otherwise

startDiscovery

Added in API level 5
fun startDiscovery(): Boolean

Start the remote device discovery process.

The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

This is an asynchronous call, it will return immediately. Register for ACTION_DISCOVERY_STARTED and ACTION_DISCOVERY_FINISHED intents to determine exactly when the discovery starts and completes. Register for android.bluetooth.BluetoothDevice#ACTION_FOUND to be notified as remote Bluetooth devices are found.

Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery. Discovery is not managed by the Activity, but is run as a system service, so an application should always call BluetoothAdapter.cancelDiscovery() even if it did not directly request a discovery, just to be sure.

Device discovery will only find remote devices that are currently discoverable (inquiry scan enabled). Many Bluetooth devices are not discoverable by default, and need to be entered into a special mode.

If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

If a device is currently bonding, this request will be queued and executed once that device has finished bonding. If a request is already queued, this request will be ignored.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
In addition, this requires either the Manifest.permission.ACCESS_FINE_LOCATION permission or a strong assertion that you will never derive the physical location of the device. You can make this assertion by declaring usesPermissionFlags="neverForLocation" on the relevant <uses-permission> manifest tag, but it may restrict the types of Bluetooth devices you can interact with.
Requires android.Manifest.permission#BLUETOOTH_SCAN

Return
Boolean true on success, false on error

startLeScan

Added in API level 18
Deprecated in API level 21
fun startLeScan(callback: BluetoothAdapter.LeScanCallback!): Boolean

Deprecated: use BluetoothLeScanner.startScan(List, ScanSettings, ScanCallback) instead.

Starts a scan for Bluetooth LE devices.

Results of the scan are reported using the LeScanCallback.onLeScan callback.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
In addition, this requires either the Manifest.permission.ACCESS_FINE_LOCATION permission or a strong assertion that you will never derive the physical location of the device. You can make this assertion by declaring usesPermissionFlags="neverForLocation" on the relevant <uses-permission> manifest tag, but it may restrict the types of Bluetooth devices you can interact with.
Requires android.Manifest.permission#BLUETOOTH_SCAN

Parameters
callback BluetoothAdapter.LeScanCallback!: the callback LE scan results are delivered
Return
Boolean true, if the scan was started successfully

startLeScan

Added in API level 18
Deprecated in API level 21
fun startLeScan(
    serviceUuids: Array<UUID!>!,
    callback: BluetoothAdapter.LeScanCallback!
): Boolean

Deprecated: use BluetoothLeScanner.startScan(List, ScanSettings, ScanCallback) instead.

Starts a scan for Bluetooth LE devices, looking for devices that advertise given services.

Devices which advertise all specified services are reported using the android.bluetooth.BluetoothAdapter.LeScanCallback#onLeScan callback.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
In addition, this requires either the Manifest.permission.ACCESS_FINE_LOCATION permission or a strong assertion that you will never derive the physical location of the device. You can make this assertion by declaring usesPermissionFlags="neverForLocation" on the relevant <uses-permission> manifest tag, but it may restrict the types of Bluetooth devices you can interact with.
Requires android.Manifest.permission#BLUETOOTH_SCAN

Parameters
serviceUuids Array<UUID!>!: Array of services to look for
callback BluetoothAdapter.LeScanCallback!: the callback LE scan results are delivered
Return
Boolean true, if the scan was started successfully

stopLeScan

Added in API level 18
Deprecated in API level 21
fun stopLeScan(callback: BluetoothAdapter.LeScanCallback!): Unit

Deprecated: Use BluetoothLeScanner.stopScan(ScanCallback) instead.

Stops an ongoing Bluetooth LE device scan.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag.
For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_SCAN permission which can be gained with android.app.Activity#requestPermissions(String[], int).
Requires android.Manifest.permission#BLUETOOTH_SCAN

Parameters
callback BluetoothAdapter.LeScanCallback!: used to identify which scan to stop must be the same handle used to start the scan

Protected methods

finalize

Added in API level 5
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method