lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey
added in API level 18

BluetoothManager

public final class BluetoothManager
extends Object

java.lang.Object
   ↳ android.bluetooth.BluetoothManager


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

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

Developer Guides

For more information about using BLUETOOTH, read the Bluetooth developer guide.

Instances of this class must be obtained using Context.getSystemService(Class) with the argument BluetoothManager.class or Context.getSystemService(String) with the argument Context.BLUETOOTH_SERVICE.

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

Summary

Public methods

BluetoothAdapter getAdapter()

Get the default BLUETOOTH Adapter for this device.

List<BluetoothDevice> getConnectedDevices(int profile)

Get connected devices for the specified profile.

int getConnectionState(BluetoothDevice device, int profile)

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

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

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

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.

Inherited methods

Public methods

getAdapter

added in API level 18
public BluetoothAdapter getAdapter ()

Get the default BLUETOOTH Adapter for this device.

Returns
BluetoothAdapter the default BLUETOOTH Adapter

getConnectedDevices

added in API level 18
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

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.

Requires the BLUETOOTH permission.

Parameters
profile int: GATT or GATT_SERVER

Returns
List<BluetoothDevice> List of devices. The list will be empty on error.

getConnectionState

added in API level 18
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.

Requires the BLUETOOTH permission.

Parameters
device BluetoothDevice: Remote bluetooth device.

profile int: GATT or GATT_SERVER

Returns
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
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.

Requires the BLUETOOTH permission.

Parameters
profile int: GATT or GATT_SERVER

states int: Array of states. States can be one of BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_DISCONNECTING,

Returns
List<BluetoothDevice> List of devices. The list will be empty on error.

openGattServer

added in API level 18
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.

Parameters
context Context: App context

callback BluetoothGattServerCallback: GATT server callback handler that will receive asynchronous callbacks.

Returns
BluetoothGattServer BluetoothGattServer instance