Added in API level 37

Builder


class Builder
kotlin.Any
   ↳ android.bluetooth.BluetoothGattConnectionSettings.Builder

Builder for BluetoothGattConnectionSettings.

Summary

Public constructors

Creates a new Builder for BluetoothGattConnectionSettings.

Public methods
BluetoothGattConnectionSettings

Builds a BluetoothGattConnectionSettings object.

BluetoothGattConnectionSettings.Builder
setAutoConnectEnabled(autoConnectEnabled: Boolean)

Setting this to true will enable the automatic connection to remote device when It is available.

BluetoothGattConnectionSettings.Builder
setAutomaticMtuEnabled(automaticMtuEnabled: Boolean)

Sets if the MTU (Maximum Transmission Unit) needs to be negotiated for given connection or not.

BluetoothGattConnectionSettings.Builder
setOpportunisticEnabled(opportunisticEnabled: Boolean)

Sets whether this GATT client is opportunistic.

BluetoothGattConnectionSettings.Builder
setPathlossThresholdDb(pathlossThresholdDb: Int)

Sets the Pathloss threshold for initiating a connection.

BluetoothGattConnectionSettings.Builder
setRssiThresholdDbm(rssiThresholdDbm: Int)

Sets the RSSI threshold for initiating a connection.

BluetoothGattConnectionSettings.Builder
setTransport(transport: Int)

Sets the transport for this Gatt settings.

Public constructors

Builder

Added in API level 37
Builder()

Creates a new Builder for BluetoothGattConnectionSettings.

Public methods

build

Added in API level 37
fun build(): BluetoothGattConnectionSettings

Builds a BluetoothGattConnectionSettings object.

Return
BluetoothGattConnectionSettings A new BluetoothGattConnectionSettings object with the configured parameters.
This value cannot be null.
Exceptions
java.lang.IllegalArgumentException on invalid parameters

setAutoConnectEnabled

Added in API level 37
fun setAutoConnectEnabled(autoConnectEnabled: Boolean): BluetoothGattConnectionSettings.Builder

Setting this to true will enable the automatic connection to remote device when It is available. Setting it to False would trigger direct connect to remote device

Parameters
autoConnectEnabled Boolean: true if auto connection is enabled, false otherwise.
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setAutomaticMtuEnabled

Added in API level 37
fun setAutomaticMtuEnabled(automaticMtuEnabled: Boolean): BluetoothGattConnectionSettings.Builder

Sets if the MTU (Maximum Transmission Unit) needs to be negotiated for given connection or not. This is set to true by default so that MTU exchange happens after the connection. Applications have to set it to false to disable the automatic negotiation. Setting this to false does not prevent MTU negotiation if a client explicitly requests it using BluetoothGatt.requestMtu or if it's triggered internally by other profiles.

Parameters
automaticMtuEnabled Boolean: true if Default MTU setting needs to be applied on this connection, false otherwise.
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setOpportunisticEnabled

Added in API level 37
fun setOpportunisticEnabled(opportunisticEnabled: Boolean): BluetoothGattConnectionSettings.Builder

Sets whether this GATT client is opportunistic. An opportunistic GATT client does not hold a GATT connection. It automatically disconnects when no other GATT connections are active for the remote device

Parameters
opportunisticEnabled Boolean: true if this connection is opportunistic, false otherwise.
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setPathlossThresholdDb

fun setPathlossThresholdDb(pathlossThresholdDb: Int): BluetoothGattConnectionSettings.Builder

Sets the Pathloss threshold for initiating a connection. If the device is already connected, then the GATT connection will succeed regardless of the Pathloss Threshold.

The Pathloss threshold is used to initiate an LE connection to a remote device when autoConnect is enabled. When autoConnect is enabled, the Bluetooth controller will add the remote device to the accept list and initiate the connection when the device is in range and has minimal pathloss. The Bluetooth controller will initiate the connection if the Pathloss is lower than the given Pathloss threshold value.

This is just a preference for the Bluetooth controller; the controller may or may not use this pathloss threshold value to initiate the connection.

When multiple applications request connections with different pathloss threshold values, the Bluetooth system will use the maximum of pathloss threshold among all active requests when initiating the next LE connection based on pathloss threshold.

Default pathloss threshold will be set to PATHLOSS_THRESHOLD_NOT_SET which indicates that pathloss based LE connection trigger is not enabled.

When the Pathloss is not available, or this value is PATHLOSS_THRESHOLD_NOT_SET, then system will fall back to the RSSI threshold based connection trigger if RSSI threshold is set using setRssiThresholdDbm

Parameters
pathlossThresholdDb Int: the pathloss threshold in dB for initiating connection.
Value is between -1 and 100 inclusive
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setRssiThresholdDbm

fun setRssiThresholdDbm(rssiThresholdDbm: Int): BluetoothGattConnectionSettings.Builder

Sets the RSSI threshold for initiating a connection. If the device is already connected, then the GATT connection will succeed regardless of the RSSI.

The RSSI threshold is used to initiate an LE connection to a remote device when autoConnect is enabled. When autoConnect is enabled, the Bluetooth controller will add the remote device to the accept list and initiate the connection when the device is in range and has a strong signal. The Bluetooth controller will initiate the connection if the RSSI is greater than the given RSSI threshold value.

This is just a preference for the Bluetooth controller; the controller may or may not use this threshold to initiate the connection.

When multiple applications request connections with different RSSI threshold values, the Bluetooth system will use the lowest (least stringent) RSSI threshold among all active requests when initiating the next LE connection based on signal strength, allowing connections to be initiated at weaker signal levels if any app requests it.

Default RSSI threshold will be set to RSSI_THRESHOLD_NOT_SET which indicates that RSSI based LE connection trigger is not enabled.

Pathloss threshold set using setPathlossThresholdDb will be prioritized over RSSI threshold for triggering LE connection. RSSI threshold will be used for triggering LE connection only if pathloss threshold is not set.

Parameters
rssiThresholdDbm Int: the RSSI threshold in dBm for initiating connection.
Value is between -128 and 20 inclusive
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setTransport

Added in API level 37
fun setTransport(transport: Int): BluetoothGattConnectionSettings.Builder

Sets the transport for this Gatt settings. preferred transport for GATT connections to remote dual-mode devices.

Parameters
transport Int: Value is one of the following:
Return
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.