BluetoothGattConnectionSettings.Builder


public static final class BluetoothGattConnectionSettings.Builder
extends Object

java.lang.Object
   ↳ android.bluetooth.BluetoothGattConnectionSettings.Builder


Builder for BluetoothGattConnectionSettings.

Summary

Public constructors

Builder()

Creates a new Builder for BluetoothGattConnectionSettings.

Public methods

BluetoothGattConnectionSettings build()

Builds a BluetoothGattConnectionSettings object.

BluetoothGattConnectionSettings.Builder setAutoConnectEnabled(boolean autoConnectEnabled)

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

BluetoothGattConnectionSettings.Builder setAutomaticMtuEnabled(boolean automaticMtuEnabled)

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

BluetoothGattConnectionSettings.Builder setOpportunisticEnabled(boolean opportunisticEnabled)

Sets whether this GATT client is opportunistic.

BluetoothGattConnectionSettings.Builder setPathlossThresholdDb(int pathlossThresholdDb)

Sets the Pathloss threshold for initiating a connection.

BluetoothGattConnectionSettings.Builder setRssiThresholdDbm(int rssiThresholdDbm)

Sets the RSSI threshold for initiating a connection.

BluetoothGattConnectionSettings.Builder setTransport(int transport)

Sets the transport for this Gatt settings.

Inherited methods

Public constructors

Builder

Added in API level 37
public Builder ()

Creates a new Builder for BluetoothGattConnectionSettings.

Public methods

build

Added in API level 37
public BluetoothGattConnectionSettings build ()

Builds a BluetoothGattConnectionSettings object.

Returns
BluetoothGattConnectionSettings A new BluetoothGattConnectionSettings object with the configured parameters.
This value cannot be null.

Throws
IllegalArgumentException on invalid parameters

setAutoConnectEnabled

Added in API level 37
public BluetoothGattConnectionSettings.Builder setAutoConnectEnabled (boolean autoConnectEnabled)

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.

Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setAutomaticMtuEnabled

Added in API level 37
public BluetoothGattConnectionSettings.Builder setAutomaticMtuEnabled (boolean automaticMtuEnabled)

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.

Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setOpportunisticEnabled

Added in API level 37
public BluetoothGattConnectionSettings.Builder setOpportunisticEnabled (boolean opportunisticEnabled)

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.

Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setPathlossThresholdDb

Added in API level 10000
public BluetoothGattConnectionSettings.Builder setPathlossThresholdDb (int pathlossThresholdDb)

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 BluetoothGattConnectionSettings.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 BluetoothGattConnectionSettings.PATHLOSS_THRESHOLD_NOT_SET, then system will fall back to the RSSI threshold based connection trigger if RSSI threshold is set using setRssiThresholdDbm(int)

Parameters
pathlossThresholdDb int: the pathloss threshold in dB for initiating connection.
Value is between -1 and 100 inclusive

Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setRssiThresholdDbm

Added in API level 10000
public BluetoothGattConnectionSettings.Builder setRssiThresholdDbm (int rssiThresholdDbm)

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 BluetoothGattConnectionSettings.RSSI_THRESHOLD_NOT_SET which indicates that RSSI based LE connection trigger is not enabled.

Pathloss threshold set using setPathlossThresholdDb(int) 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

Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.

setTransport

Added in API level 37
public BluetoothGattConnectionSettings.Builder setTransport (int transport)

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:
Returns
BluetoothGattConnectionSettings.Builder This builder.
This value cannot be null.