Added in API level 18

BluetoothManager

class BluetoothManager
kotlin.Any
   ↳ android.bluetooth.BluetoothManager

High level manager used to obtain an instance of an BluetoothAdapter and to conduct overall Bluetooth Management.

Use android.content.Context#getSystemService(java.lang.String) with android.content.Context#BLUETOOTH_SERVICE to create an BluetoothManager, then call getAdapter to obtain the BluetoothAdapter.


Requires the PackageManager#FEATURE_BLUETOOTH feature which can be detected using PackageManager.hasSystemFeature(String).

Summary

Public methods
BluetoothAdapter!

Get the BLUETOOTH Adapter for this device.

MutableList<BluetoothDevice!>!

Get connected devices for the specified profile.

Int
getConnectionState(device: BluetoothDevice!, profile: Int)

Get the current connection state of the profile to the remote device.

MutableList<BluetoothDevice!>!

Get a list of devices that match any of the given connection states.

BluetoothGattServer!

Open a GATT Server The callback is used to deliver results to Caller, such as connection status as well as the results of any other GATT server operations.

Public methods

getAdapter

Added in API level 18
fun getAdapter(): BluetoothAdapter!

Get the BLUETOOTH Adapter for this device.

Return
BluetoothAdapter! the BLUETOOTH Adapter

getConnectedDevices

Added in API level 18
fun getConnectedDevices(profile: Int): MutableList<BluetoothDevice!>!

Get connected devices for the specified profile.

Return the set of devices which are in state BluetoothProfile#STATE_CONNECTED

This is not specific to any application configuration but represents the connection state of Bluetooth for this profile. This can be used by applications like status bar which would just like to know the state of Bluetooth.
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
profile Int: GATT or GATT_SERVER
Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

getConnectionState

Added in API level 18
fun getConnectionState(
    device: BluetoothDevice!,
    profile: Int
): Int

Get the current connection state of the profile to the remote device.

This is not specific to any application configuration but represents the connection state of the local Bluetooth adapter for certain profile. This can be used by applications like status bar which would just like to know the state of Bluetooth.
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
device BluetoothDevice!: Remote bluetooth device.
profile Int: GATT or GATT_SERVER
Return
Int State of the profile connection. One of BluetoothProfile#STATE_CONNECTED, BluetoothProfile#STATE_CONNECTING, BluetoothProfile#STATE_DISCONNECTED, BluetoothProfile#STATE_DISCONNECTING

getDevicesMatchingConnectionStates

Added in API level 18
fun getDevicesMatchingConnectionStates(
    profile: Int,
    states: IntArray!
): MutableList<BluetoothDevice!>!

Get a list of devices that match any of the given connection states.

If none of the devices match any of the given states, an empty list will be returned.

This is not specific to any application configuration but represents the connection state of the local Bluetooth adapter for this profile. This can be used by applications like status bar which would just like to know the state of the local adapter.
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
profile Int: GATT or GATT_SERVER
states IntArray!: Array of states. States can be one of BluetoothProfile#STATE_CONNECTED, BluetoothProfile#STATE_CONNECTING, BluetoothProfile#STATE_DISCONNECTED, BluetoothProfile#STATE_DISCONNECTING,
Return
MutableList<BluetoothDevice!>! List of devices. The list will be empty on error.

openGattServer

Added in API level 18
fun openGattServer(
    context: Context!,
    callback: BluetoothGattServerCallback!
): BluetoothGattServer!

Open a GATT Server The callback is used to deliver results to Caller, such as connection status as well as the results of any other GATT server operations. The method returns a BluetoothGattServer instance. You can use BluetoothGattServer to conduct GATT server operations.
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
context Context!: App context
callback BluetoothGattServerCallback!: GATT server callback handler that will receive asynchronous callbacks.
Return
BluetoothGattServer! BluetoothGattServer instance