public final class BluetoothManager extends Object
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
.
Alternately, you can just call the static helper
BluetoothAdapter.getDefaultAdapter()
.
For more information about using BLUETOOTH, read the Bluetooth developer guide.
Constructor and Description |
---|
BluetoothManager(Context context) |
Modifier and Type | Method and Description |
---|---|
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.
|
BluetoothGattServer |
openGattServer(Context context,
BluetoothGattServerCallback callback,
int transport)
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 BluetoothManager(Context context)
public BluetoothAdapter getAdapter()
public int getConnectionState(BluetoothDevice device, int profile)
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 android.Manifest.permission#BLUETOOTH
permission.
device
- Remote bluetooth device.profile
- GATT or GATT_SERVERBluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
,
BluetoothProfile.STATE_DISCONNECTING
public List<BluetoothDevice> getConnectedDevices(int 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 android.Manifest.permission#BLUETOOTH
permission.
profile
- GATT or GATT_SERVERpublic List<BluetoothDevice> getDevicesMatchingConnectionStates(int profile, int[] 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 android.Manifest.permission#BLUETOOTH
permission.
profile
- GATT or GATT_SERVERstates
- Array of states. States can be one of
BluetoothProfile.STATE_CONNECTED
, BluetoothProfile.STATE_CONNECTING
,
BluetoothProfile.STATE_DISCONNECTED
,
BluetoothProfile.STATE_DISCONNECTING
,public BluetoothGattServer openGattServer(Context context, BluetoothGattServerCallback callback)
context
- App contextcallback
- GATT server callback handler that will receive asynchronous callbacks.public BluetoothGattServer openGattServer(Context context, BluetoothGattServerCallback callback, int transport)
context
- App contextcallback
- GATT server callback handler that will receive asynchronous callbacks.transport
- preferred transport for GATT connections to remote dual-mode devices
BluetoothDevice.TRANSPORT_AUTO
or
BluetoothDevice.TRANSPORT_BREDR
or BluetoothDevice.TRANSPORT_LE