public class BluetoothPeripheralManager
extends java.lang.Object
Constructor and Description |
---|
BluetoothPeripheralManager(@NotNull android.content.Context context,
@NotNull android.bluetooth.BluetoothManager bluetoothManager,
@NotNull BluetoothPeripheralManagerCallback callback)
Create a BluetoothPeripheralManager
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(@NotNull android.bluetooth.BluetoothGattService service)
Add a service to the peripheral
|
void |
cancelConnection(@NotNull BluetoothCentral bluetoothCentral)
Cancel a connection to a Central
|
void |
close()
Close the BluetoothPeripheralManager
Application should call this method as early as possible after it is done with
this BluetoothPeripheralManager.
|
@Nullable BluetoothCentral |
getCentral(@NotNull java.lang.String address) |
@NotNull java.util.Set<BluetoothCentral> |
getConnectedCentrals()
Get the set of connected Centrals
|
@NotNull java.util.List<android.bluetooth.BluetoothGattService> |
getServices()
Get a list of the all advertised services of this peripheral
|
boolean |
notifyCharacteristicChanged(@NotNull byte[] value,
@NotNull android.bluetooth.BluetoothGattCharacteristic characteristic)
Send a notification or indication that a local characteristic has been
updated
|
boolean |
remove(@NotNull android.bluetooth.BluetoothGattService service)
Remove a service
|
void |
removeAllServices()
Remove all services
|
void |
startAdvertising(@NotNull android.bluetooth.le.AdvertiseSettings settings,
@NotNull android.bluetooth.le.AdvertiseData advertiseData,
@NotNull android.bluetooth.le.AdvertiseData scanResponse)
Start Bluetooth LE Advertising.
|
void |
stopAdvertising()
Stop advertising
|
public BluetoothPeripheralManager(@NotNull @NotNull android.content.Context context, @NotNull @NotNull android.bluetooth.BluetoothManager bluetoothManager, @NotNull @NotNull BluetoothPeripheralManagerCallback callback)
context
- the application contextbluetoothManager
- a valid BluetoothManagercallback
- an instance of BluetoothPeripheralManagerCallback where the callbacks will be handledpublic void close()
public void startAdvertising(@NotNull @NotNull android.bluetooth.le.AdvertiseSettings settings, @NotNull @NotNull android.bluetooth.le.AdvertiseData advertiseData, @NotNull @NotNull android.bluetooth.le.AdvertiseData scanResponse)
advertiseData
will be broadcasted if the
operation succeeds. The scanResponse
is returned when a scanning device sends an
active scan request. This method returns immediately, the operation status is delivered
through BluetoothPeripheralManagerCallback.onAdvertisingStarted(AdvertiseSettings)
or BluetoothPeripheralManagerCallback.onAdvertiseFailure(AdvertiseError)
.settings
- the AdvertiseSettingsadvertiseData
- the AdvertiseDatascanResponse
- the ScanResponsepublic void stopAdvertising()
public boolean add(@NotNull @NotNull android.bluetooth.BluetoothGattService service)
Once a service has been added to the list, the service and its included characteristics will be provided by the local peripheral.
If the local peripheral has already exposed services when this function
is called, a service update notification will be sent to all clients.
A callback on BluetoothPeripheralManagerCallback.onServiceAdded(com.welie.blessed.GattStatus, android.bluetooth.BluetoothGattService)
will be received when this operation has completed
service
- the service to addpublic boolean remove(@NotNull @NotNull android.bluetooth.BluetoothGattService service)
service
- the service to removepublic void removeAllServices()
@NotNull public @NotNull java.util.List<android.bluetooth.BluetoothGattService> getServices()
public boolean notifyCharacteristicChanged(@NotNull @NotNull byte[] value, @NotNull @NotNull android.bluetooth.BluetoothGattCharacteristic characteristic)
A notification or indication is sent to all remote centrals to signal that the characteristic has been updated.
characteristic
- the characteristic for which to send a notificationpublic void cancelConnection(@NotNull @NotNull BluetoothCentral bluetoothCentral)
bluetoothCentral
- the Central@NotNull public @NotNull java.util.Set<BluetoothCentral> getConnectedCentrals()
@Nullable public @Nullable BluetoothCentral getCentral(@NotNull @NotNull java.lang.String address)