# BluetoothManager

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/bluetooth/BluetoothManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/bluetooth/BluetoothManager#inhmethods)  

# BluetoothManager

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothManager "View this page in Kotlin")\|Java

`
public

final

class
BluetoothManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.bluetooth.BluetoothManager |

<br />

*** ** * ** ***

High level manager used to obtain an instance of an[BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter)and to conduct overall Bluetooth Management.

Use[Context.getSystemService(java.lang.String)](https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.String))with[Context.BLUETOOTH_SERVICE](https://developer.android.com/reference/android/content/Context#BLUETOOTH_SERVICE)to create an[BluetoothManager](https://developer.android.com/reference/android/bluetooth/BluetoothManager), then call[getAdapter()](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getAdapter())to obtain the[BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter).  

### Developer Guides

For more information about using BLUETOOTH, read the[Bluetooth](https://developer.android.com/guide/topics/connectivity/bluetooth)developer guide.

Requires the[PackageManager#FEATURE_BLUETOOTH](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_BLUETOOTH)feature which can be detected using[PackageManager.hasSystemFeature(String)](https://developer.android.com/reference/android/content/pm/PackageManager#hasSystemFeature(java.lang.String)).

<br />

**See also:**

- [Context.getSystemService(Class)](https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.Class<T>))
- [BluetoothAdapter.getDefaultAdapter()](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getDefaultAdapter())

## Summary

|                                                                                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                                                                                  ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter)                                                                   | ` `[getAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getAdapter())`() ` Get the BluetoothAdapter for this device.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` `[List](https://developer.android.com/reference/java/util/List)`<`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice)`>` | ` `[getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int))`(int profile) ` Get connected devices for the specified profile.                                                                                                                                                                                                                                                                                                                                                                                 |
| ` int`                                                                                                                                                              | ` `[getConnectionState](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectionState(android.bluetooth.BluetoothDevice,%20int))`(`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice)` device, int profile) ` Get the current connection state of the profile to the remote device.                                                                                                                                                                                                                  |
| ` `[List](https://developer.android.com/reference/java/util/List)`<`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice)`>` | ` `[getDevicesMatchingConnectionStates](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getDevicesMatchingConnectionStates(int,%20int[]))`(int profile, int[] states) ` Get a list of devices that match any of the given connection states.                                                                                                                                                                                                                                                                                                        |
| ` `[BluetoothGattServer](https://developer.android.com/reference/android/bluetooth/BluetoothGattServer)                                                             | ` `[openGattServer](https://developer.android.com/reference/android/bluetooth/BluetoothManager#openGattServer(android.content.Context,%20android.bluetooth.BluetoothGattServerCallback))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[BluetoothGattServerCallback](https://developer.android.com/reference/android/bluetooth/BluetoothGattServerCallback)` callback) ` 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. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### getAdapter

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public BluetoothAdapter getAdapter ()
```

Get the BluetoothAdapter for this device.

<br />

|                                                           Returns                                                           ||
|------------------------------------------------------------------------------------------------|-----------------------------|
| [BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter) | the BluetoothAdapter <br /> |

### getConnectedDevices

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public List<BluetoothDevice> getConnectedDevices (int profile)
```

Get connected devices for the specified profile.

Return the set of devices which are in state[BluetoothProfile.STATE_CONNECTED](https://developer.android.com/reference/android/bluetooth/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](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)or lower, this requires the[Manifest.permission.BLUETOOTH](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH)permission which can be gained with a simple`<uses-permission>`manifest tag.  
For apps targeting[Build.VERSION_CODES.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S)or or higher, this requires the[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)permission which can be gained with[Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).  
Requires[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)

<br />

|                  Parameters                  ||
|-----------|-----------------------------------|
| `profile` | `int`: GATT or GATT_SERVER <br /> |

|                                                                                                          Returns                                                                                                           ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [List](https://developer.android.com/reference/java/util/List)`<`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice)`>` | List of devices. The list will be empty on error. <br /> |

### getConnectionState

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getConnectionState (BluetoothDevice device, 
                int profile)
```

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](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)or lower, this requires the[Manifest.permission.BLUETOOTH](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH)permission which can be gained with a simple`<uses-permission>`manifest tag.  
For apps targeting[Build.VERSION_CODES.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S)or or higher, this requires the[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)permission which can be gained with[Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).  
Requires[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)

<br />

|                          Parameters                           ||
|-----------|----------------------------------------------------|
| `device`  | `BluetoothDevice`: Remote bluetooth device. <br /> |
| `profile` | `int`: GATT or GATT_SERVER <br />                  |

|                                                                                                                                                                                                                                                                                             Returns                                                                                                                                                                                                                                                                                              ||
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | State of the profile connection. One of[BluetoothProfile.STATE_CONNECTED](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTED),[BluetoothProfile.STATE_CONNECTING](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTING),[BluetoothProfile.STATE_DISCONNECTED](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_DISCONNECTED),[BluetoothProfile.STATE_DISCONNECTING](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_DISCONNECTING) <br /> |

### getDevicesMatchingConnectionStates

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public List<BluetoothDevice> getDevicesMatchingConnectionStates (int profile, 
                int[] states)
```

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](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)or lower, this requires the[Manifest.permission.BLUETOOTH](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH)permission which can be gained with a simple`<uses-permission>`manifest tag.  
For apps targeting[Build.VERSION_CODES.S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S)or or higher, this requires the[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)permission which can be gained with[Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).  
Requires[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)

<br />

|                                                                                                                                                                                                                                                                                                 Parameters                                                                                                                                                                                                                                                                                                 ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `profile` | `int`: GATT or GATT_SERVER <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `states`  | `int`: Array of states. States can be one of[BluetoothProfile.STATE_CONNECTED](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTED),[BluetoothProfile.STATE_CONNECTING](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTING),[BluetoothProfile.STATE_DISCONNECTED](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_DISCONNECTED),[BluetoothProfile.STATE_DISCONNECTING](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_DISCONNECTING), <br /> |

|                                                                                                          Returns                                                                                                           ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [List](https://developer.android.com/reference/java/util/List)`<`[BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice)`>` | List of devices. The list will be empty on error. <br /> |

### openGattServer

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public BluetoothGattServer openGattServer (Context context, 
                BluetoothGattServerCallback callback)
```

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](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S)or or higher, this requires the[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)permission which can be gained with[Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).  
Requires[Manifest.permission.BLUETOOTH_CONNECT](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)

<br />

|                                                        Parameters                                                        ||
|------------|--------------------------------------------------------------------------------------------------------------|
| `context`  | `Context`: App context <br />                                                                                |
| `callback` | `BluetoothGattServerCallback`: GATT server callback handler that will receive asynchronous callbacks. <br /> |

|                                                                  Returns                                                                  ||
|------------------------------------------------------------------------------------------------------|-------------------------------------|
| [BluetoothGattServer](https://developer.android.com/reference/android/bluetooth/BluetoothGattServer) | BluetoothGattServer instance <br /> |