title: Android: Auto-reconnect BLE devices
body: <p>My goal is to get the Android device to reconnect to a BLE device that it has previously connected to <strong>without user intervention</strong> in the same way it does for a classic BT paired device does (even works through power cycles).</p>
  
  <p>One of the ideas of BTLE devices is that one saves service, bonding, and enabling states such that a reconnect is VERY fast and consumes very little power on the peripheral.</p>
  
  <p>What I have done seems to work but it works poorly.</p>
  
  <p>The first step is to connect or pair and connect to a new device setting the 'autoconnect' parameter to 'true'.
  When the device disconnects, <em>do not call</em> gatt.close(). Everywhere I look I see that one should call gatt.close(). But if I do call gatt.close() the Android central app never reconnects. I have tested this many times.</p>
  
  <p>If I have not called gatt.close() and have not power cycled the Android, the auto-connection usually happens. Sometimes it can take a long time, especially after version 5.0. It is, however, unreliable and it may be unreliable due to a very low-duty scan cycle and the device quitting advertising before a scan cycle actually detects the advertisement. I am not sure because there is no way to detect the scanning operation like there is advertisements! It is also possible the scanning stops after a certain amount of time but there is no documentation on that.</p>
  
  <p>So what I think I need to do is to somehow set the background scan rate used by the Android to a higher duty cycle (only possible in 5.0 and up) when auto-connect has been set but I do not know how to do this. I do not want to start my own scan but somehow set the background scanning rate used by Android for the reconnect. Does anyone know how to do this? Does anyone really know how autoconnect and gatt.close() are to work?</p>
  
  <p>Maybe the auto-connect was NOT meant to re-connect as I indicated above?</p>