My goal is to connect an Android device to a BLE device that it previously connected to without user intervention , in the same way as a classic BT pairing device (even works through power cycles).
One of the ideas of BTLE devices is that one maintains a state of service, communication, and permission, so reconnecting is VERY fast and consumes very little power on the periphery.
What I did seems to work, but it works poorly.
The first step is to connect or pair and connect to a new device, setting the auto-connect option to true. When the device shuts down, do not call gatt.close (). Wherever I look, I see what needs to be called gatt.close (). But if I call gatt.close (), the central Android application will never reconnect. I have tested this many times.
If I did not call gatt.close () and did not turn on the power of Android, usually an automatic connection occurs. This can sometimes be time consuming, especially after version 5.0. However, it is unreliable and may be unreliable due to the very low scan cycle, and the device exits the advertisement before the scan cycle actually detects the advertisement. I'm not sure, because there is no way to detect a scan operation, as there is an advertisement! It is also possible that the scan will stop after a certain time, but there is no documentation on it.
So, it seems to me that I need to make sure that the background scan frequency used by Android is set to a higher duty cycle (maybe only in 5.0 and higher) when auto-connect is established, but I donβt know how to do it. I do not want to run my own scan, but somehow set the background scan frequency used by Android to reconnect. Does anyone know how to do this? Does anyone really know how autoconnect and gatt.close () work?
Maybe the auto-join was NOT intended to reconnect, as described above?