Most visited

Recently visited

Added in API level 18

BluetoothGattServerCallback

public abstract class BluetoothGattServerCallback
extends Object

java.lang.Object
   ↳ android.bluetooth.BluetoothGattServerCallback


这个抽象类用于实现 BluetoothGattServer回调。

Summary

Public constructors

BluetoothGattServerCallback()

Public methods

void onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic)

远程客户端已经请求读取本地特征。

void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)

远程客户端已请求写入本地特征。

void onConnectionStateChange(BluetoothDevice device, int status, int newState)

回叫指示何时远程设备已连接或断开连接。

void onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor)

远程客户端请求读取本地描述符。

void onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)

远程客户端已请求写入本地描述符。

void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute)

执行此设备的所有挂起写入操作。

void onMtuChanged(BluetoothDevice device, int mtu)

指示给定设备连接的MTU的回叫已更改。

void onNotificationSent(BluetoothDevice device, int status)

当通知或指示已发送到远程设备时调用回调。

void onServiceAdded(int status, BluetoothGattService service)

指示本地服务是否已成功添加。

Inherited methods

From class java.lang.Object

Public constructors

BluetoothGattServerCallback

Added in API level 18
BluetoothGattServerCallback ()

Public methods

onCharacteristicReadRequest

Added in API level 18
void onCharacteristicReadRequest (BluetoothDevice device, 
                int requestId, 
                int offset, 
                BluetoothGattCharacteristic characteristic)

远程客户端已经请求读取本地特征。

应用程序必须致电 sendResponse(BluetoothDevice, int, int, int, byte[])才能完成请求。

Parameters
device BluetoothDevice: The remote device that has requested the read operation
requestId int: The Id of the request
offset int: Offset into the value of the characteristic
characteristic BluetoothGattCharacteristic: Characteristic to be read

onCharacteristicWriteRequest

Added in API level 18
void onCharacteristicWriteRequest (BluetoothDevice device, 
                int requestId, 
                BluetoothGattCharacteristic characteristic, 
                boolean preparedWrite, 
                boolean responseNeeded, 
                int offset, 
                byte[] value)

远程客户端已请求写入本地特征。

应用程序必须调用 sendResponse(BluetoothDevice, int, int, int, byte[])来完成请求。

Parameters
device BluetoothDevice: The remote device that has requested the write operation
requestId int: The Id of the request
characteristic BluetoothGattCharacteristic: Characteristic to be written to.
preparedWrite boolean: true, if this write operation should be queued for later execution.
responseNeeded boolean: true, if the remote device requires a response
offset int: The offset given for the value
value byte: The value the client wants to assign to the characteristic

onConnectionStateChange

Added in API level 18
void onConnectionStateChange (BluetoothDevice device, 
                int status, 
                int newState)

回叫指示何时远程设备已连接或断开连接。

Parameters
device BluetoothDevice: Remote device that has been connected or disconnected.
status int: Status of the connect or disconnect operation.
newState int: Returns the new connection state. Can be one of STATE_DISCONNECTED or STATE_CONNECTED

onDescriptorReadRequest

Added in API level 18
void onDescriptorReadRequest (BluetoothDevice device, 
                int requestId, 
                int offset, 
                BluetoothGattDescriptor descriptor)

远程客户端请求读取本地描述符。

应用程序必须致电 sendResponse(BluetoothDevice, int, int, int, byte[])才能完成请求。

Parameters
device BluetoothDevice: The remote device that has requested the read operation
requestId int: The Id of the request
offset int: Offset into the value of the characteristic
descriptor BluetoothGattDescriptor: Descriptor to be read

onDescriptorWriteRequest

Added in API level 18
void onDescriptorWriteRequest (BluetoothDevice device, 
                int requestId, 
                BluetoothGattDescriptor descriptor, 
                boolean preparedWrite, 
                boolean responseNeeded, 
                int offset, 
                byte[] value)

远程客户端已请求写入本地描述符。

应用程序必须致电 sendResponse(BluetoothDevice, int, int, int, byte[])才能完成请求。

Parameters
device BluetoothDevice: The remote device that has requested the write operation
requestId int: The Id of the request
descriptor BluetoothGattDescriptor: Descriptor to be written to.
preparedWrite boolean: true, if this write operation should be queued for later execution.
responseNeeded boolean: true, if the remote device requires a response
offset int: The offset given for the value
value byte: The value the client wants to assign to the descriptor

onExecuteWrite

Added in API level 18
void onExecuteWrite (BluetoothDevice device, 
                int requestId, 
                boolean execute)

执行此设备的所有挂起写入操作。

应用程序必须致电 sendResponse(BluetoothDevice, int, int, int, byte[])才能完成请求。

Parameters
device BluetoothDevice: The remote device that has requested the write operations
requestId int: The Id of the request
execute boolean: Whether the pending writes should be executed (true) or cancelled (false)

onMtuChanged

Added in API level 22
void onMtuChanged (BluetoothDevice device, 
                int mtu)

指示给定设备连接的MTU的回叫已更改。

如果远程客户端请求更改给定连接的MTU,则会调用此回调。

Parameters
device BluetoothDevice: The remote device that requested the MTU change
mtu int: The new MTU size

onNotificationSent

Added in API level 21
void onNotificationSent (BluetoothDevice device, 
                int status)

当通知或指示已发送到远程设备时调用回调。

当发送多个通知时,应用程序必须等待发送附加通知之前收到此回调。

Parameters
device BluetoothDevice: The remote device the notification has been sent to
status int: GATT_SUCCESS if the operation was successful

onServiceAdded

Added in API level 18
void onServiceAdded (int status, 
                BluetoothGattService service)

指示本地服务是否已成功添加。

Parameters
status int: Returns GATT_SUCCESS if the service was added successfully.
service BluetoothGattService: The service that has been added

Hooray!