Android Question [SOLVED] BLE Stops finding devices

SimonInCanada

Member
Licensed User
I am using the BLE2 Library V1.38 and the latest B4A. The app is used to calibrate BLE-based equipment that I designed and generally works well. The company selected a generic tablet to issue to the calibration companies, the idea being that a standard device is easier to support, even though it works well on all devices it has been tried on. The testers just found that after a number of Scan - Connect - Disconnect cycles that Scan fails to find any further devices (even the ones it found a minute ago). In this situation, closing our app with the BACK key or from the "recently running apps" list does not help. Only restarting the tablet will work (every time).

The tablet is called a MediaTek QT-10 claiming to be Android 7 but actually reports Android 5 (SDK 22) to API calls and certainly behaves that way, i.e. you can still read the Bluetooth Address which stopped working with Android 6.

The app has been tried on various other Android devices (mostly various staff's Samsung phones, fablets etc) and this behaviour has not been seen on the other devices.

Can anyone suggest a workaround that does not involve restarting the tablet?
 

JohnC

Expert
Licensed User
Longtime User
As a worse-cause workaround, maybe try re-initializing the BLEManager before each manually-invoked scan (instead of having to reboot the device).
 
Upvote 0

SimonInCanada

Member
Licensed User
As a worse-cause workaround, maybe try re-initializing the BLEManager before each manually-invoked scan (instead of having to reboot the device).
Thanks. My app was based on the example for the BLE2Manager and still has a starter service which normally initialises BLE. I added a callable sub to the service with the call
manager.Initialize("manager")
which the program calls if a scan is terminated by the user resulting in finding no devices. *This does not work*. I don't think it is doing anything, because once the problem has started, calls to start a scan take a second or so longer (usually very fast) and the delay was still there after initialize hasd been called.
 
Upvote 0

SimonInCanada

Member
Licensed User
I have found a workaround that works. In the Serial library there is a BluetoothManager object which is illustrated in the standard Bluetooth Chat example and which I had used before. It turns out that this has the same capabilities as the phone/tablet's Bluetooth applet so can turn off and on Bluetooth, it seems including BLE.

So I declare an instance of BluetoothManager at the start of my program and initialise it. I added buttons to call the Disable and Enable methods and some code to handle and log its StatusChanged event. I did not make any change to the existing BLE code.

After say 9 scan - connect - disconnect sequences I then click the disable button and wait for the Log to show that the status is now disabled. I then click on enable and again wait a second or so for its status to change. I can then go ahead and make say 9 more scan - connect - disconnect sequences, then I have to repeat the disabling - enabling of BluetoothManager. It seems that I can keep repeating this for ever, though I will most likely disable and re-enable automatically after each single sequence just to be sure.

If I try just closing or killing the app after say 9 sequences, this doesn't work and I end with the BLE finding nothing again.
 
Upvote 0
Top