java.lang.Object | |
↳ | android.bluetooth.BluetoothGattServer |
Public API for the Bluetooth GATT Profile server role.
This class provides Bluetooth GATT server role functionality, allowing applications to create and advertise Bluetooth Smart services and characteristics.
BluetoothGattServer is a proxy object for controlling the Bluetooth Service
via IPC. Use getProfileProxy(Context, BluetoothProfile.ServiceListener, int)
to get the
BluetoothGatt proxy object.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.bluetooth.BluetoothProfile
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a service to the list of services to be hosted.
| |||||||||||
Disconnects an established connection, or cancels a connection attempt
currently in progress.
| |||||||||||
Remove all services from the list of provided services.
| |||||||||||
Close this GATT server instance.
| |||||||||||
Initiate a connection to a Bluetooth GATT capable device.
| |||||||||||
Not supported - please use
getConnectedDevices(int)
with GATT as argument | |||||||||||
Not supported - please use
getConnectedDevices(int)
with GATT as argument | |||||||||||
Not supported - please use
getDevicesMatchingConnectionStates(int, int[])
with GATT as first argument | |||||||||||
Returns a
BluetoothGattService from the list of services offered
by this device. | |||||||||||
Returns a list of GATT services offered by this device.
| |||||||||||
Send a notification or indication that a local characteristic has been
updated.
| |||||||||||
Removes a service from the list of services to be provided.
| |||||||||||
Send a response to a read or write request to a remote device.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.bluetooth.BluetoothProfile
|
Add a service to the list of services to be hosted.
Once a service has been addded to the the list, the service and it's included characteristics will be provided by the local device.
If the local device has already exposed services when this function is called, a service update notification will be sent to all clients.
Requires BLUETOOTH
permission.
service | Service to be added to the list of services provided by this device. |
---|
Disconnects an established connection, or cancels a connection attempt currently in progress.
Requires BLUETOOTH
permission.
device | Remote device |
---|
Remove all services from the list of provided services.
Requires BLUETOOTH
permission.
Close this GATT server instance. Application should call this method as early as possible after it is done with this GATT server.
Initiate a connection to a Bluetooth GATT capable device.
The connection may not be established right away, but will be
completed when the remote device is available. A
onConnectionStateChange(BluetoothDevice, int, int)
callback will be
invoked when the connection state changes as a result of this function.
The autoConnect paramter determines whether to actively connect to the remote device, or rather passively scan and finalize the connection when the remote device is in range/available. Generally, the first ever connection to a device should be direct (autoConnect set to false) and subsequent connections to known devices should be invoked with the autoConnect parameter set to true.
Requires BLUETOOTH
permission.
autoConnect | Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true). |
---|
Not supported - please use getConnectedDevices(int)
with GATT
as argument
Not supported - please use getConnectedDevices(int)
with GATT
as argument
device | Remote bluetooth device. |
---|
STATE_CONNECTED
, STATE_CONNECTING
,
STATE_DISCONNECTED
, STATE_DISCONNECTING
Not supported - please use
getDevicesMatchingConnectionStates(int, int[])
with GATT
as first argument
states | Array of states. States can be one of
STATE_CONNECTED , STATE_CONNECTING ,
STATE_DISCONNECTED , STATE_DISCONNECTING , |
---|
Returns a BluetoothGattService
from the list of services offered
by this device.
If multiple instances of the same service (as identified by UUID) exist, the first instance of the service is returned.
Requires BLUETOOTH
permission.
uuid | UUID of the requested service |
---|
Returns a list of GATT services offered by this device.
An application must call addService(BluetoothGattService)
to add a serice to the
list of services offered by this device.
Requires BLUETOOTH
permission.
Send a notification or indication that a local characteristic has been updated.
A notification or indication is sent to the remote device to signal that the characteristic has been updated. This function should be invoked for every client that requests notifications/indications by writing to the "Client Configuration" descriptor for the given characteristic.
Requires BLUETOOTH
permission.
device | The remote device to receive the notification/indication |
---|---|
characteristic | The local characteristic that has been updated |
confirm | true to request confirmation from the client (indication), false to send a notification |
Removes a service from the list of services to be provided.
Requires BLUETOOTH
permission.
service | Service to be removed. |
---|
Send a response to a read or write request to a remote device.
This function must be invoked in when a remote read/write request is received by one of these callback methods:
onCharacteristicReadRequest(BluetoothDevice, int, int, BluetoothGattCharacteristic)
onCharacteristicWriteRequest(BluetoothDevice, int, BluetoothGattCharacteristic, boolean, boolean, int, byte[])
onDescriptorReadRequest(BluetoothDevice, int, int, BluetoothGattDescriptor)
onDescriptorWriteRequest(BluetoothDevice, int, BluetoothGattDescriptor, boolean, boolean, int, byte[])
Requires BLUETOOTH
permission.
device | The remote device to send this response to |
---|---|
requestId | The ID of the request that was received with the callback |
status | The status of the request to be sent to the remote devices |
offset | Value offset for partial read/write response |
value | The value of the attribute that was read/written (optional) |