@@ -210,6 +210,41 @@ public ConnectRequest useAutoConnect(final boolean autoConnect) {
210210 return this ;
211211 }
212212
213+ /**
214+ * Sets whether to connect to the remote device just once (autoConnect == false) or to add
215+ * the address to white list of devices that will be automatically connect as soon as they
216+ * become available (autoConnect == true). In the latter case, if Bluetooth adapter is enabled,
217+ * Android scans periodically for devices from the white list and, if an advertising packet
218+ * is received from such, it tries to connect to it.
219+ * When the connection is lost, the system will keep trying to reconnect to
220+ * it. If method is called with autoConnect set to true, and the connection to the device is
221+ * lost, the {@link BleManagerCallbacks#onLinkLossOccurred(BluetoothDevice)} callback is
222+ * called instead of {@link BleManagerCallbacks#onDeviceDisconnected(BluetoothDevice)}.
223+ * <p>
224+ * This feature works much better on newer Android phone models and may have issues on older
225+ * phones.
226+ * <p>
227+ * This method should only be used with bonded devices, as otherwise the device may change
228+ * it's address. It will however work also with non-bonded devices with private static address.
229+ * A connection attempt to a non-bonded device with private resolvable address will fail.
230+ * <p>
231+ * If createDirectConnectionFirst is set to true, the first connection to a device will always be
232+ * created with autoConnect flag to false
233+ * (see {@link BluetoothDevice#connectGatt(Context, boolean, BluetoothGattCallback)}). This is
234+ * to make it quick as the user most probably waits for a quick response. If autoConnect is
235+ * used (true), the following connections will be done using {@link BluetoothGatt#connect()},
236+ * which forces the autoConnect parameter to true.
237+ * If autoConnect is used (true) and createDirectConnectionFirst is set to false, the connection
238+ * to a device will be created with autoConnect flag to true from the start.
239+ *
240+ * @param autoConnect true to use autoConnect feature.
241+ * @param createDirectConnectionFirst If true, the first connection is always done with autoConnect
242+ * parameter equal to false, to make it faster and allow to timeout
243+ * if the device is unreachable.
244+ * If false, the connection to a device will be created with
245+ * autoConnect flag to true from the start.
246+ * @return The request.
247+ */
213248 public ConnectRequest useAutoConnect (final boolean autoConnect , final boolean createDirectConnectionFirst ) {
214249 this .autoConnect = autoConnect ;
215250 this .autoConnectCreateDirectConnectionFirst = createDirectConnectionFirst ;
0 commit comments