public class BleDeviceConfig extends BleNodeConfig implements java.lang.Cloneable
BleDevice.setConfig(BleDeviceConfig)
.
This class is also a super class of BleManagerConfig
, which you can pass
to BleManager.get(Context, BleManagerConfig)
or BleManager.setConfig(BleManagerConfig)
to set default base options for all devices at once.
For all options in this class, you may set the value to null
when passed to BleDevice.setConfig(BleDeviceConfig)
and the value will then be inherited from the BleManagerConfig
passed to BleManager.get(Context, BleManagerConfig)
.
Otherwise, if the value is not null
it will override any option in the BleManagerConfig
.
If an option is ultimately null
(null
when passed to BleDevice.setConfig(BleDeviceConfig)
*and* BleManager.get(Context, BleManagerConfig)
) then it is interpreted as false
or Interval.DISABLED
.
Interval.DISABLED
instead of null
to disable any keepalive-based options, for code readability's sake.
newNulled()
(or BleNodeConfig.nullOut()
) then only set the few options you want for BleDevice.setConfig(BleDeviceConfig)
.Modifier and Type | Class and Description |
---|---|
static interface |
BleDeviceConfig.AuthTransactionFactory<T extends BleTransaction.Auth> |
static class |
BleDeviceConfig.DefaultBondFilter
Default implementation of
BondFilter that unbonds for certain phone models upon discovery and disconnects. |
static interface |
BleDeviceConfig.InitTransactionFactory<T extends BleTransaction.Init> |
static class |
BleDeviceConfig.RefreshOption
Enumeration used with
useGattRefresh . |
BleNodeConfig.DefaultHistoricalDataLogFilter, BleNodeConfig.DefaultTaskTimeoutRequestFilter, BleNodeConfig.HistoricalDataFactory, BleNodeConfig.HistoricalDataLogFilter
Modifier and Type | Field and Description |
---|---|
java.lang.Boolean |
allowDuplicatePollEntries
Default is
false - if true and you call BleDevice.startPoll(UUID, Interval, ReadWriteListener)
or BleDevice.startChangeTrackingPoll(UUID, Interval, ReadWriteListener)() with identical
parameters then two identical polls would run which would probably be wasteful and unintentional. |
boolean |
alwaysBondOnConnect
Default is
false - Controls whether SweetBlue will automatically bond when connecting to a peripheral (rather than letting Android do it itself). |
java.lang.Boolean |
autoBondFixes
Default is
true - By default SweetBlue will force a bond/unbond for certain phones (mostly Sony, Motorola) because it has been found to
improve connection rates with them, see BondFilter docs. |
boolean |
autoEnableNotifiesOnReconnect
Default is
true - whether to automatically enable notifications that were enabled via a call to any of the enableNotify() methods
in BleDevice upon device reconnection. |
java.lang.Boolean |
autoGetServices
Default is
true - whether to automatically get services immediately after a BleDevice is
BleDeviceState.BLE_CONNECTED . |
boolean |
autoNegotiateMtuOnReconnect
Default is
true - whether to automatically renegotiate the MTU size that was set via BleDevice.negotiateMtu(int, ReadWriteListener) , or
BleDevice.negotiateMtu(int) . |
java.lang.Boolean |
autoReconnectDeviceWhenBleTurnsBackOn
Default is
true - if devices are kept in memory for a BleManager.turnOff() /BleManager.turnOn() cycle
(or a BleManager.reset() ) because retainDeviceWhenBleTurnsOff is true , then a BleDevice.connect()
will be attempted for any devices that were previously BleDeviceState.BLE_CONNECTED . |
IBluetoothDevice.Factory |
bluetoothDeviceFactory
This option is exposed for unit testing.
|
BondFilter |
bondFilter
Default is instance of
BleDeviceConfig.DefaultBondFilter . |
java.lang.Boolean |
bondingFailFailsConnection
Default is
true - controls whether DeviceReconnectFilter.Status.BONDING_FAILED is capable of
inducing ReconnectFilter.onConnectFailed(ReconnectFilter.ConnectFailEvent)
while a device is BleDeviceState.CONNECTING_OVERALL . |
BondRetryFilter |
bondRetryFilter
Default is
BondRetryFilter.DefaultBondRetryFilter - This allows to you implement your own logic on whether or not SweetBlue should
retry a failed bond. |
java.lang.Boolean |
cacheDeviceOnUndiscovery
Default is
true - controls whether a BleDevice is placed into an in-memory cache when it becomes BleDeviceState.UNDISCOVERED . |
boolean |
clearGattOnOtaSuccess
Default is
false . |
java.lang.Boolean |
connectFailRetryConnectingOverall
Default is
true - whether SweetBlue should retry a connect after successfully connecting via
BLE. |
Interval |
connectionBugFixTimeout
Default is
DEFAULT_CONNECTION_BUG_FIX_TIMEOUT . |
static int |
DEFAULT_CONNECTION_BUG_FIX_TIMEOUT
The default value used for
connectionBugFixTimeout . |
static int |
DEFAULT_GATT_REFRESH_DELAY
This only applies when
useGattRefresh is true . |
static int |
DEFAULT_MAX_BOND_RETRIES
The default value used for
BondRetryFilter.DefaultBondRetryFilter . |
static int |
DEFAULT_MAX_CONNECTION_FAIL_HISTORY_SIZE
The default value of
maxConnectionFailHistorySize , the size of the list that keeps track of a BleNode 's connection failure history. |
static double |
DEFAULT_MINIMUM_SCAN_TIME
Default value for
minScanTimeNeededForUndiscovery . |
static double |
DEFAULT_RSSI_AUTO_POLL_RATE
Default value for
rssiAutoPollRate . |
static int |
DEFAULT_RSSI_MAX
Default fallback value for
rssi_max . |
static int |
DEFAULT_RSSI_MIN
Default fallback value for
rssi_min . |
static int |
DEFAULT_RUNNING_AVERAGE_N
Default value for
nForAverageRunningReadTime and nForAverageRunningWriteTime . |
static double |
DEFAULT_SCAN_KEEP_ALIVE
This is a good default value for
undiscoveryKeepAlive . |
static int |
DEFAULT_TX_POWER
Default value for
defaultTxPower . |
BleDeviceConfig.AuthTransactionFactory |
defaultAuthFactory
Set a default
BleTransaction.Auth factory which will be used to dispatch a new instance
of the transaction when connecting to a BleDevice . |
BleDeviceState[] |
defaultDeviceStates
Default is
BleDeviceState.DEFAULT_STATES . |
BleDeviceConfig.InitTransactionFactory |
defaultInitFactory
Set a default
BleTransaction.Init factory which will be used to dispatch a new instance
of the transaction when connecting to a BleDevice . |
BleTransaction.Atomicity |
defaultTransactionAtomicity
This is the default
BleTransaction.Atomicity that will be used for all BleTransaction . |
java.lang.Integer |
defaultTxPower
Default is
DEFAULT_TX_POWER - this value is used if we can't establish a device's calibrated transmission power from the device itself,
either through its scan record or by reading the standard characteristic. |
boolean |
equalOpportunityReadsWrites
Default is
false - SweetBlue tries to manage task priority for best performance. |
boolean |
forceBondDialog
Default is
false . |
Interval |
forceBondHackInterval
Default is
Interval.ONE_SEC . |
IBluetoothGatt.Factory |
gattFactory
This option is exposed for unit testing.
|
Interval |
gattRefreshDelay
Default is
DEFAULT_GATT_REFRESH_DELAY . |
BleDeviceConfig.RefreshOption |
gattRefreshOption
Default is
BleDeviceConfig.RefreshOption.BEFORE_SERVICE_DISCOVERY - This determines when SweetBlue will refresh the gatt database. |
java.lang.Boolean |
includeOtaReadWriteTimesInAverage
Default is
false - BleDevice.getAverageReadTime() and BleDevice.getAverageWriteTime() can be
skewed if the peripheral you are connecting to adjusts its maximum throughput for OTA firmware updates and the like. |
java.lang.Boolean |
manageLastDisconnectOnDisk
Default is
true - controls whether the State.ChangeIntent behind a device going BleDeviceState.BLE_DISCONNECTED
is saved to and loaded from disk so that it can be restored across app sessions, undiscoveries, and BLE
BleManagerState.OFF ->BleManagerState.ON cycles. |
int |
maxConnectionFailHistorySize
Default is
DEFAULT_MAX_CONNECTION_FAIL_HISTORY_SIZE - This sets the size of the list that tracks the history
of ReconnectFilter.ConnectFailEvent s. |
Interval |
minScanTimeNeededForUndiscovery
Default is
DEFAULT_MINIMUM_SCAN_TIME seconds - Undiscovery of devices must be
approximated by checking when the last time was that we discovered a device,
and if this time is greater than undiscoveryKeepAlive then the device is undiscovered. |
MtuTestCallback |
mtuTestCallback
Default is
null - This callback is used after calling BleDevice.negotiateMtu(int, ReadWriteListener) or BleDevice.negotiateMtu(int) , if the
negotiation was successful, and provides a way to know if the test failed/succeeded. |
java.lang.Integer |
nForAverageRunningReadTime
Default is
DEFAULT_RUNNING_AVERAGE_N - Same thing as nForAverageRunningWriteTime but for reads. |
java.lang.Integer |
nForAverageRunningWriteTime
Default is
DEFAULT_RUNNING_AVERAGE_N - The number of historical write times that the library should keep track of when calculating average time. |
Phy |
phyOptions
Default is
Phy.DEFAULT . |
ReconnectFilter |
reconnectFilter
Default is an instance of
DefaultReconnectFilter using the timings that are public static final members thereof - set your own implementation here to
have fine-grain control over reconnect behavior while a device is BleDeviceState.RECONNECTING_LONG_TERM or BleDeviceState.RECONNECTING_SHORT_TERM . |
java.lang.Boolean |
retainDeviceWhenBleTurnsOff
Default is
true - controls whether BleManager will keep a device in active memory when it goes BleManagerState.OFF . |
java.lang.Integer |
rssi_max
Default is
DEFAULT_RSSI_MAX - the estimated maximum value for BleDevice.getRssi() . |
java.lang.Integer |
rssi_min
Default is
DEFAULT_RSSI_MIN - the estimated minimum value for BleDevice.getRssi() . |
Interval |
rssiAutoPollRate
Default is
DEFAULT_RSSI_AUTO_POLL_RATE - The rate at which a BleDevice will automatically poll for its BleDevice.getRssi() value
after it's BleDeviceState.BLE_CONNECTED . |
java.lang.Boolean |
saveNameChangesToDisk
Default is
true - controls whether changes to a device's name through BleDevice.setName(String) are remembered on disk through
SharedPreferences . |
Interval |
serviceDiscoveryDelay
Default is
Interval.DISABLED . |
java.lang.Boolean |
tryBondingWhileDisconnected
Default is
true - some devices can only reliably become BleDeviceState.BONDED while BleDeviceState.BLE_DISCONNECTED ,
so this option controls whether the library will internally change any bonding flow dictated by bondFilter when a bond fails and try
to bond again the next time the device is BleDeviceState.BLE_DISCONNECTED . |
java.lang.Boolean |
tryBondingWhileDisconnected_manageOnDisk
Deprecated.
This option will be removed in v3.1. It just adds extra complexity when it's not really needed. If your device needs to be bonded, then
set
alwaysBondOnConnect to true , or manually call BleDevice.bond() . |
java.lang.Boolean |
undiscoverDeviceWhenBleTurnsOff
Default is
true - only applicable if retainDeviceWhenBleTurnsOff is also true. |
Interval |
undiscoveryKeepAlive
Default is disabled - If a device exceeds this amount of time since its
last discovery then it is a candidate for being undiscovered.
|
java.lang.Boolean |
useGattRefresh
Default is
false - whether to use BluetoothGatt.refresh() right before service discovery. |
java.lang.Boolean |
useLeTransportForBonding
The below explanation is wrong, only in that the default is now
false . |
alwaysUseAutoConnect, autoStripeWrites, DEFAULT_MTU_SIZE, disconnectIsCancellable, GATT_READ_MTU_OVERHEAD, GATT_WRITE_MTU_OVERHEAD, historicalDataFactory, historicalDataLogFilter, INVALID_TX_POWER, taskTimeoutRequestFilter
Constructor and Description |
---|
BleDeviceConfig()
Creates a
BleDeviceConfig with all default options set. |
BleDeviceConfig(org.json.JSONObject jo)
Creates a
BleDeviceConfig with all default options set. |
Modifier and Type | Method and Description |
---|---|
BleDeviceConfig |
clone() |
static BleDeviceConfig |
newNulled()
Convenience method that returns a nulled out
BleDeviceConfig , which is useful
when using BleDevice.setConfig(BleDeviceConfig) to only override a few options
from BleManagerConfig passed to BleManager.get(Context, BleManagerConfig)
or BleManager.setConfig(BleManagerConfig) . |
getTimeout, nullOut, readJSON, writeJSON
public static final double DEFAULT_MINIMUM_SCAN_TIME
minScanTimeNeededForUndiscovery
.public static final int DEFAULT_RUNNING_AVERAGE_N
nForAverageRunningReadTime
and nForAverageRunningWriteTime
.public static final double DEFAULT_SCAN_KEEP_ALIVE
undiscoveryKeepAlive
. By default undiscoveryKeepAlive
is Interval.DISABLED
.public static final double DEFAULT_RSSI_AUTO_POLL_RATE
rssiAutoPollRate
.public static final int DEFAULT_RSSI_MIN
rssi_min
.public static final int DEFAULT_RSSI_MAX
rssi_max
.public static final int DEFAULT_TX_POWER
defaultTxPower
.public static final int DEFAULT_MAX_CONNECTION_FAIL_HISTORY_SIZE
maxConnectionFailHistorySize
, the size of the list that keeps track of a BleNode
's connection failure history.
This is to prevent the list from growing too large, if the device is unable to connect, and you have a large long term reconnect time set
with reconnectFilter
.public static final int DEFAULT_GATT_REFRESH_DELAY
useGattRefresh
is true
. This is the default amount of time to delay after
refreshing the gatt database before actually performing the discover services operation. It has been observed that this delay
alleviates some instability when useGattRefresh
is true
.public static final int DEFAULT_MAX_BOND_RETRIES
BondRetryFilter.DefaultBondRetryFilter
. Bond retries only apply when calling BleDevice.bond()
, or BleDevice.bond(BondListener)
.
Like connecting, sometimes in order to get bonding to work, you just have to try multiple times. If you require bonding for the device you're connecting
to, it's recommended to use one of the bond methods.public static final int DEFAULT_CONNECTION_BUG_FIX_TIMEOUT
connectionBugFixTimeout
. Android leaves a connection open to a device on it's first bond. As the fix for this is rather
convoluted, the library has a timeout to forget about the fix if it hits this timeout value. This value is in seconds.public Interval connectionBugFixTimeout
DEFAULT_CONNECTION_BUG_FIX_TIMEOUT
. This sets the timeout length for the connection open bug.DEFAULT_CONNECTION_BUG_FIX_TIMEOUT
public Phy phyOptions
Phy.DEFAULT
. This setting is only really used for Bluetooth 5 devices. The android device needs to be running Oreo for any option other than
Phy.DEFAULT
to work (if not, SweetBlue will fall back to the default option). This allows you to specify if SweetBlue should use the high speed,
long range, or default features. Set it here to be applied to the device after connecting, or you can also call BleDevice.setPhyOptions(Phy)
public boolean forceBondDialog
false
. If the bluetooth device you are trying to connect to requires a pairing dialog to show up, you should
set this to true
. Android will do one of two things when you try to pair to the device. It will either A) show the pairing dialog, or
B) show a notification in the notification area. When B happens, most people probably won't notice it, and think your app can't connect to the device.
This uses an ugly hack to get the dialog to always display...it starts a CLASSIC bluetooth scan for a second, then stops it, and starts the bond. As crazy
as it sounds, it works. Note that no devices will be discovered during this one second scan.public Interval forceBondHackInterval
Interval.ONE_SEC
. This setting only applies if forceBondDialog
is true
. This sets the amount of time to run the classic
scan for before attempting to bond. If this is set to Interval.DISABLED
, or is null
, and forceBondDialog
is set to true
,
then the default value will be used.forceBondDialog
public Interval gattRefreshDelay
DEFAULT_GATT_REFRESH_DELAY
. This only applies when useGattRefresh
is true
. This is the amount of time to delay after
refreshing the gatt database before actually performing the discover services operation. It has been observed that this delay
alleviates some instability when useGattRefresh
is true
.public Interval serviceDiscoveryDelay
Interval.DISABLED
. This option adds a delay between establishing a BLE connection, and service discovery, if autoGetServices
is
true
. This value will be ignored if useGattRefresh
is true
, as the library will use gattRefreshDelay
instead.public java.lang.Boolean tryBondingWhileDisconnected
true
- some devices can only reliably become BleDeviceState.BONDED
while BleDeviceState.BLE_DISCONNECTED
,
so this option controls whether the library will internally change any bonding flow dictated by bondFilter
when a bond fails and try
to bond again the next time the device is BleDeviceState.BLE_DISCONNECTED
.
@Deprecated public java.lang.Boolean tryBondingWhileDisconnected_manageOnDisk
alwaysBondOnConnect
to true
, or manually call BleDevice.bond()
.false
- controls whether any bonding issues worked around if tryBondingWhileDisconnected
is true
are remembered on disk
(through SharedPreferences
) so that bonding is as stable as possible across application sessions.public boolean alwaysBondOnConnect
false
- Controls whether SweetBlue will automatically bond when connecting to a peripheral (rather than letting Android do it itself).
If the device is already bonded, this will do nothing. In most cases, it's best to bond before connecting, but there are rare devices which work better
to bond after becoming connected. To adjust this behavior, adjust tryBondingWhileDisconnected
(if it's true
, then the bond will happen
before connecting, otherwise it will happen after).public BleDeviceState[] defaultDeviceStates
BleDeviceState.DEFAULT_STATES
. This specifies which BleDeviceState
s should be posted to the DeviceStateListener
. The default contains
all the states an app should care about. If you want more fine grained state changes (for debugging for instance), then you can specify which states you want to know about
here.public java.lang.Boolean saveNameChangesToDisk
true
- controls whether changes to a device's name through BleDevice.setName(String)
are remembered on disk through
SharedPreferences
. If true, this means calls to BleDevice.getName_override()
will return the same thing
even across app restarts.public ReconnectFilter reconnectFilter
DefaultReconnectFilter
using the timings that are public static final
members thereof - set your own implementation here to
have fine-grain control over reconnect behavior while a device is BleDeviceState.RECONNECTING_LONG_TERM
or BleDeviceState.RECONNECTING_SHORT_TERM
.
This is basically how often and how long the library attempts to reconnect to a device that for example may have gone out of range. Set this variable to
null
if reconnect behavior isn't desired. If not null
, your app may find
BleManagerConfig.manageCpuWakeLock
useful in order to force the app/phone to stay awake while attempting a reconnect.public java.lang.Boolean autoGetServices
true
- whether to automatically get services immediately after a BleDevice
is
BleDeviceState.BLE_CONNECTED
. Currently this is the only way to get a device's services.public boolean autoEnableNotifiesOnReconnect
true
- whether to automatically enable notifications that were enabled via a call to any of the enableNotify() methods
in BleDevice
upon device reconnection. Basically, if you enable notifications in an BleTransaction.Init
transaction,
then set this to false
, as the transaction will run on reconnection.public boolean autoNegotiateMtuOnReconnect
true
- whether to automatically renegotiate the MTU size that was set via BleDevice.negotiateMtu(int, ReadWriteListener)
, or
BleDevice.negotiateMtu(int)
. If you use either of those methods in a BleTransaction.Init
transaction, you should set
this to false
, as the transaction will run on reconnection.public MtuTestCallback mtuTestCallback
null
- This callback is used after calling BleDevice.negotiateMtu(int, ReadWriteListener)
or BleDevice.negotiateMtu(int)
, if the
negotiation was successful, and provides a way to know if the test failed/succeeded. If the MTU test fails, SweetBlue will disconnect the device, as it won't work beyond
that point anyway (depending on your settings, SweetBlue may reconnect automatically for you).public java.lang.Boolean allowDuplicatePollEntries
false
- if true
and you call BleDevice.startPoll(UUID, Interval, ReadWriteListener)
or BleDevice.startChangeTrackingPoll(UUID, Interval, ReadWriteListener)()
with identical
parameters then two identical polls would run which would probably be wasteful and unintentional.
This option provides a defense against that situation.public java.lang.Boolean includeOtaReadWriteTimesInAverage
false
- BleDevice.getAverageReadTime()
and BleDevice.getAverageWriteTime()
can be
skewed if the peripheral you are connecting to adjusts its maximum throughput for OTA firmware updates and the like.
Use this option to let the library know whether you want read/writes to factor in while BleDeviceState.PERFORMING_OTA
.public java.lang.Boolean retainDeviceWhenBleTurnsOff
true
- controls whether BleManager
will keep a device in active memory when it goes BleManagerState.OFF
.
If false
then a device will be purged and you'll have to do BleManager.startScan()
again to discover devices
if/when BleManager
goes back BleManagerState.ON
.
BleManagerConfig
passed to BleManager.get(Context, BleManagerConfig)
then this
applies to all devices.public java.lang.Boolean undiscoverDeviceWhenBleTurnsOff
true
- only applicable if retainDeviceWhenBleTurnsOff
is also true. If retainDeviceWhenBleTurnsOff
is false then devices will be undiscovered when BleManager
goes BleManagerState.OFF
regardless.
retainDeviceWhenBleTurnsOff
for how this applies to BleManagerConfig
.public java.lang.Boolean autoReconnectDeviceWhenBleTurnsBackOn
true
- if devices are kept in memory for a BleManager.turnOff()
/BleManager.turnOn()
cycle
(or a BleManager.reset()
) because retainDeviceWhenBleTurnsOff
is true
, then a BleDevice.connect()
will be attempted for any devices that were previously BleDeviceState.BLE_CONNECTED
.
retainDeviceWhenBleTurnsOff
for how this applies to BleManagerConfig
.retainDeviceWhenBleTurnsOff
public java.lang.Boolean manageLastDisconnectOnDisk
true
- controls whether the State.ChangeIntent
behind a device going BleDeviceState.BLE_DISCONNECTED
is saved to and loaded from disk so that it can be restored across app sessions, undiscoveries, and BLE
BleManagerState.OFF
->BleManagerState.ON
cycles. This uses Android's SharedPreferences
so does not require
any extra permissions. The main advantage of this is the following scenario: User connects to a device through your app,
does what they want, kills the app, then opens the app sometime later. BleDevice.getLastDisconnectIntent()
returns
State.ChangeIntent.UNINTENTIONAL
, which lets you know that you can probably automatically connect to this device without user confirmation.public java.lang.Boolean cacheDeviceOnUndiscovery
true
- controls whether a BleDevice
is placed into an in-memory cache when it becomes BleDeviceState.UNDISCOVERED
.
If true
, subsequent calls to GenericListener_Void.onEvent(Event)
with
DiscoveryListener.LifeCycle.DISCOVERED
(or calls to BleManager.newDevice(String)
) will return the cached BleDevice
instead of creating a new one.
BleDevice.getAdvertisedServices()
for future discovery events.
See also minScanTimeNeededForUndiscovery
.
public java.lang.Boolean bondingFailFailsConnection
true
- controls whether DeviceReconnectFilter.Status.BONDING_FAILED
is capable of
inducing ReconnectFilter.onConnectFailed(ReconnectFilter.ConnectFailEvent)
while a device is BleDeviceState.CONNECTING_OVERALL
.public java.lang.Boolean useGattRefresh
false
- whether to use BluetoothGatt.refresh()
right before service discovery.
This method is not in the public Android API, so its use is disabled by default. You may find it useful to enable
if your remote device is routinely changing its gatt service profile. This method call supposedly clears a cache
that would otherwise prevent changes from being discovered.public BleDeviceConfig.RefreshOption gattRefreshOption
BleDeviceConfig.RefreshOption.BEFORE_SERVICE_DISCOVERY
- This determines when SweetBlue will refresh the gatt database.
This only applies if you have set useGattRefresh
to true
.public boolean clearGattOnOtaSuccess
false
. When set to true
, this will clear the gatt database that is cached after
BleTransaction.Ota.succeed()
is called. This is useful when you are performing a firmware update using the
BleTransaction.Ota
class, and the gatt database has changed as a result.public java.lang.Boolean connectFailRetryConnectingOverall
true
- whether SweetBlue should retry a connect after successfully connecting via
BLE. This means that if discovering services, or BleTransaction.Init
, or BleTransaction.Auth
fail for any reason, SweetBlue will disconnect, then retry the connection.public java.lang.Boolean useLeTransportForBonding
false
. This is for backwards
compatibility, as a customer noted bonding not working after this change. This will most likely go back to being
true
when version 3 comes out.
Default is true
- The normal way to bond in the native API is to use BluetoothDevice.createBond()
.
There is however also a overload method that's made invisible using the "hide" annotation that takes an int
representing the desired transport mode. The default for BluetoothDevice.createBond()
is BluetoothDevice.TRANSPORT_AUTO
.
You can look at the source to see that this is the case. The thing is, you *never* want the Android stack to automatically decide something.
So if you set useLeTransportForBonding
to true then SweetBlue will use the "private" overloaded method with
BluetoothDevice.TRANSPORT_LE
. This workaround anecdotally fixed bonding issues with LG G4 and Samsung S6 phones.
Anecdotally because the public BluetoothDevice.createBond()
was not working, tried the private one, it worked,
but then the public BluetoothDevice.createBond()
also worked flawlessly after that.
But again, regardless, you should always choose explicit behavior over automatic when dealing with Android BLE.
public BondRetryFilter bondRetryFilter
BondRetryFilter.DefaultBondRetryFilter
- This allows to you implement your own logic on whether or not SweetBlue should
retry a failed bond.public java.lang.Boolean autoBondFixes
true
- By default SweetBlue will force a bond/unbond for certain phones (mostly Sony, Motorola) because it has been found to
improve connection rates with them, see BondFilter
docs. This option is here in the case you don't want this behavior (for instance, the BLE
device you're connecting to needs a pairing dialog to come up). However, you should use this at your own risk because it may make further connections
to the device less reliable.public boolean equalOpportunityReadsWrites
false
- SweetBlue tries to manage task priority for best performance. It's best to leave this alone, unless you absolutely need to change
it. The use case for this is if you always connect to several devices, and one or more of them could be unreachable. In this case, the connecting task(s) will
block any read/write calls to connected devices. Setting this option to true
will set reads/writes to the same priority as connect tasks, which means
reads, writes, and connect calls will be executed in the order they were called.public Interval minScanTimeNeededForUndiscovery
DEFAULT_MINIMUM_SCAN_TIME
seconds - Undiscovery of devices must be
approximated by checking when the last time was that we discovered a device,
and if this time is greater than undiscoveryKeepAlive
then the device is undiscovered. However a scan
operation must be allowed a certain amount of time to make sure it discovers all nearby devices that are
still advertising. This is that time in seconds.
Interval.DISABLED
to disable undiscovery altogether.public Interval undiscoveryKeepAlive
DEFAULT_SCAN_KEEP_ALIVE
.
Use Interval.DISABLED
to disable undiscovery altogether.public Interval rssiAutoPollRate
DEFAULT_RSSI_AUTO_POLL_RATE
- The rate at which a BleDevice
will automatically poll for its BleDevice.getRssi()
value
after it's BleDeviceState.BLE_CONNECTED
. You may also use BleDevice.startRssiPoll(Interval, ReadWriteListener)
for more control and feedback.public java.lang.Integer nForAverageRunningWriteTime
DEFAULT_RUNNING_AVERAGE_N
- The number of historical write times that the library should keep track of when calculating average time.public java.lang.Integer nForAverageRunningReadTime
DEFAULT_RUNNING_AVERAGE_N
- Same thing as nForAverageRunningWriteTime
but for reads.public java.lang.Integer defaultTxPower
DEFAULT_TX_POWER
- this value is used if we can't establish a device's calibrated transmission power from the device itself,
either through its scan record or by reading the standard characteristic. To get a good value for this on a per-remote-device basis
experimentally, simply run a sample app and use BleDevice.startRssiPoll(Interval, ReadWriteListener)
and spit BleDevice.getRssi()
to your log. The average value of BleDevice.getRssi()
at one meter away is the value you should use for this config option.BleDevice.getTxPower()
public java.lang.Integer rssi_min
DEFAULT_RSSI_MIN
- the estimated minimum value for BleDevice.getRssi()
.public java.lang.Integer rssi_max
DEFAULT_RSSI_MAX
- the estimated maximum value for BleDevice.getRssi()
.public BondFilter bondFilter
BleDeviceConfig.DefaultBondFilter
.BondFilter
public BleDeviceConfig.AuthTransactionFactory defaultAuthFactory
BleTransaction.Auth
factory which will be used to dispatch a new instance
of the transaction when connecting to a BleDevice
. This transaction will also be called if the BleDevice
has
to reconnect for any reason.public BleDeviceConfig.InitTransactionFactory defaultInitFactory
BleTransaction.Init
factory which will be used to dispatch a new instance
of the transaction when connecting to a BleDevice
. This transaction will also be called if the BleDevice
has
to reconnect for any reason.public BleTransaction.Atomicity defaultTransactionAtomicity
BleTransaction.Atomicity
that will be used for all BleTransaction
. You can change
this on an individual transaction basis by overloading BleTransaction.getAtomicity()
, or change it globally
with this settingpublic int maxConnectionFailHistorySize
DEFAULT_MAX_CONNECTION_FAIL_HISTORY_SIZE
- This sets the size of the list that tracks the history
of ReconnectFilter.ConnectFailEvent
s. Note that this will always be
at least 1. If set to anything lower, it will be ignored, and the max size will be 1.public IBluetoothDevice.Factory bluetoothDeviceFactory
public IBluetoothGatt.Factory gattFactory
public BleDeviceConfig()
BleDeviceConfig
with all default options set. See each member of this class
for what the default options are set to. Consider using newNulled()
also.public BleDeviceConfig(org.json.JSONObject jo)
BleDeviceConfig
with all default options set. Then, any configuration options
specified in the given JSONObject will be applied over the defaults. See BleNodeConfig.writeJSON()
regarding the creation of the JSONObjectpublic static BleDeviceConfig newNulled()
BleDeviceConfig
, which is useful
when using BleDevice.setConfig(BleDeviceConfig)
to only override a few options
from BleManagerConfig
passed to BleManager.get(Context, BleManagerConfig)
or BleManager.setConfig(BleManagerConfig)
.public BleDeviceConfig clone()
clone
in class BleNodeConfig