public class BlePeripheralManager extends Object
Your application can use this class to create BLE services and characteristics.
| 构造器 | 说明 |
|---|---|
BlePeripheralManager(Context context,
BlePeripheralManagerCallback callback,
int transport) |
A constructor used to create a
BlePeripheralManager instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
addService(GattService service) |
Adds a specified service to be hosted.
|
void |
cancelConnection(BlePeripheralDevice device) |
Disconnects an established connection or cancels an ongoing connection attempt.
|
void |
clearServices() |
Removes all services from the list of GATT services provided by this device.
|
void |
close() |
Closes this
BlePeripheralManager object and deregisters its callbacks. |
List<BlePeripheralDevice> |
getDevicesByStates(int[] states) |
Obtains the list of BLE peripheral devices in a specified state.
|
List<GattService> |
getServices() |
Obtains the list of GATT services provided by this device.
|
boolean |
notifyCharacteristicChanged(BlePeripheralDevice device,
GattCharacteristic characteristic,
boolean confirm) |
Sends a notification or indication of a change in a specified local characteristic.
|
boolean |
removeGattService(GattService service) |
Removes a specified service from the list of GATT services provided by this device.
|
boolean |
sendResponse(BlePeripheralDevice device,
int requestId,
int status,
int offset,
byte[] value) |
Sends a response to a specified read or write request to a given BLE peripheral device.
|
public BlePeripheralManager(Context context, BlePeripheralManagerCallback callback, int transport)
BlePeripheralManager instance.context - Indicates the context.callback - Indicates the callback of the BlePeripheralManager instance.transport - Indicates the data transmission type.public List<GattService> getServices()
public boolean addService(GattService service)
The added service and its characteristics are provided by the local device.
service - Indicates the service to add.true if the service is added; returns false otherwise.public void cancelConnection(BlePeripheralDevice device)
device - Indicates the BLE peripheral device.public void close()
BlePeripheralManager object and deregisters its callbacks.public void clearServices()
public List<BlePeripheralDevice> getDevicesByStates(int[] states)
states - Indicates the specified state.public boolean notifyCharacteristicChanged(BlePeripheralDevice device, GattCharacteristic characteristic, boolean confirm)
This method should be called for every BLE peripheral device that has requested notifications or indications.
device - Indicates the BLE peripheral device to receive the notification or indication.characteristic - Indicates the local characteristic that has changed.confirm - Specifies whether to request confirmation from the BLE peripheral device (indication) or
send a notification. Value true indicates the former and false indicates the latter.true if the notification or indication is sent successfully; returns false otherwise.public boolean removeGattService(GattService service)
service - Indicates the service to remove.true if the service is removed; returns false otherwise.public boolean sendResponse(BlePeripheralDevice device, int requestId, int status, int offset, byte[] value)
device - Indicates the BLE peripheral device to which to send the response.requestId - Indicates the ID of the read or write request.status - Indicates the status of the read or write request.offset - Indicates the offset for a partial read or write response.value - Indicates the attribute value that was read or written.true if the response is sent successfully; returns false otherwise.