I'm trying to make an app based on exemple 8 on this page: http://kio4.com/arduino/160_Wemos_ESP32_BLE.htm
It worked very well in the old versions of Android, but in Android 10, even updating the BluetoothLE extension, I have some problems using the app.
The first problem is that everytime that I open the app, even if Bluetooth is enabled, it does not show any device in the list. I need to click on disable connection and then enable via app to force the Android to ask the permission to enable the BLE. Every time.
The second problem is that Android loses connection to the device after a few minutes if I minimize the app. When I get back, I need to disable and enable the connection via app to receive another permission from android to acces the BLE.
And now, after updating the extension, the old versions of Android are unable to see the list of devices, so I need to make two versions of the same application, one for Andoid 10 and one for the older ones.
This is using the version 20200616 of BluetoothLE extension
Does anyone have any idea how to solve this?
There is no problem if you have to reformulate all this part of the connection.
Another thing. Is it possible to improve this system so that, when I connect a device, it will be memorized by the cell phone so that the application automatically connects to it? I tried to create a text box to enter the MAC address and save it to a file that the application would read later, but it didn't work.
The Autoreconnect property of the BLE extension, if enabled, asks Android to automatically reconnect to the last connected device when the app is active and the peripheral is within range. It will depend on how frequently the peripheral is advertising itself. This is much better than scanning for devices yourself and reconnecting since it can be offloaded to hardware.
Regarding the differences in versions, the newest version requires fine location access. If you've previously denied this permission to the companion on older Android versions you'll need to grant it in the settings app to allow the newest BLE extension to scan (this should be a one time operation).
Also, the BLE extension has nothing to do with managing whether Bluetooth is turned on/off. I believe @Juan_Antonio is the author of the extension you're using and might be able to advise further on the behavior you're experiencing there.
The problem is that without the KIO4 extension, when I open the application, it does not ask for permission from the system. It can scan, show devices, but when I open the list and click to connect, nothing happens.
Another problem is that, if I restart ESP32, if I don't click deactivate and reactivate Bluettoth to receive a new request, I will not be able to connect with the device again.
And with this new version of BluetoothLE extension, I can't find any devices in previous versions of Android. For Andoid 8 or later, only works the version 20190701.
I'm currently using a Xiaomi Redmi Note 9 Pro with Android 10, a Motorola Moto G5S with Andoid 8 and a Xiaomi Redmi 6A with Andoid 7 or 8.
About this part, I expressed myself poorly. What I want is that, once the application connects with a device, it memorizes the MAC address or something similar, and in a few days, if I use it again, it will automatically connect to the device, without me need to search for it.
AFAIK, the Android API doesn't put a timeout on how long the auto reconnection flag lasts for, so my understanding is that this should persist even after multiple days. Are you not observing that behavior?