Android app polls bluetooth devices and freezes after 80min - android

Together with a sub-company we try to develop an android app which simulates an automotive HMI system. There is a functionality to changes the color-theme in case of connected mobile-phone (via Bluetooth). In general this is working: If a known paired phone is in range the theme switches... if the phone loses connection the theme switches back...
Problem: Currently the app polls the paired bluetooth devices for every second and checks if a known phone is paired.
After ~1h and 20min (+/- 5min) the app freezes (reproducible).
Our sub-company told us, that the reason is a problem in android bluetooth device - A timer overflows and android refuses the requests of the app after this time. Thats the reason, that the app freezes.
I´m not familiar with android development and I have to believe in this statements.
Could you tell me if there are other possibilities?
Is it necessary to poll the bluetooth device? Is there nothing like an system event which could be used?
Is this problem (refused bluetooth pooling after defined time) known?
Hint: The problem occurs only with power supply. In battery usage the app runs till battery is empty (longer than 80min).
Samsung Galaxy Tab Pro with android 4.4 (same problem with android 4.3)
It would be nice if anybody is able to help.
Many thanks

Related

Can a paired/bonded bluetooth device wake an Oreo or higher Android device

I have a security system where moving a Bluetooth LE device causes my android application to do some work. After some of the newer Android updates, I believe API 26, I could no longer get these updates if the Android device's screen was off. I was trying to think of a way around this and came up with an idea:
What if I paired the Android device and the Bluetooth device - would this allow for the message to be received when the Android screen is off?
Previously, all my BLE devices were part of a mesh, so I would regularly have the Android app check for changes in the mesh and turn the screen on to notify the user if needed. Now, because of the background execution limits introduced, I must require the Android device to have the screen on at all times, which leads to the death of display over time.
I'm not that great at programming in C, which is the language the BLE chips are programmed in, so I wanted to ask this first before spending hours just to see this NOT work. So, just to repeat the question: Will having a BLE device paired with the Android device allow a message through these restrictions when the Android screen is off?
If not - is there a way I can make this work?
Thank you for any info!
Use notifications instead of advertisements. This will deliver data instantly and works even if the screen is off. Newer versions of Android have introduced more restrictions for BLE scanning when the screen is off.
Use connectGatt with autoConnect set to true to automatically connect and reconnect in case the connection drops.
Use a Foreground Service in your app process to prevent the app process from being killed. If your app process exits, all Bluetooth connections are dropped as well.
You could use CompanionDeviceManager to gain some extra permissions.
You don't really need to be paired but it has some benefits such as faster connection setup and correctly remembering the address type (flaw in the API that this is missing).

Bluetooth scanner reconnect android

I have a Samsung Galaxy Xcover 4, and a scanner (Intermec SR61).
The Samsung Galaxy XCover 4 is running an application 24/7, and never goes to sleep.
The Intermec SR61 is connected to this phone, and when scanning barcode, the application reads the barcode and handle the data.
After 24 hours, the Intermec SR61 loses connectivity to the phone.
It won't reconnect. I have to reconnect it through the application (disable/enable).
Why does this happen, and what can I do to make sure that doesn't happen?
I have created something similar and some phones connected to some scanners will do that. It is either a Bluetooth bug, a phone bug or a hardware thing.
There is not much you can do about it, I am afraid. Possibly you can change some settings in the scanner (sleep mode or something).
What I did to fix it, was to create a background process that keeps an eye on the connection and re-connects if it is gone. That process even goes so far to switch the Bluetooth adapter off and on again (because of problems on a certain phone).

Mobile Phones confused about BLE pairing

We have an IoT device that has an onboard BLE chip (Anaren A20737A) that the user can control from their mobile phone. At times, the phone will pair with the device (or at least report that it is paired), but will not receive any data, and all commands appear to be ignored by the device. Connecting the logger to the device, we can see that it believes that it is sending out messages correctly, and that it is paired with the phone. The solution appears to be forgetting the BLE pairing from the Bluetooth settings on the phone, and sometimes restarting the phone as well. No changes to the IoT device appear to have any impact, the only thing that works is forgetting the pairing from the phone's settings. This problem has occurred on both iPhone and Android (separate code bases).
EDIT
The problem is seen on iOS 7.0 and multiple versions of android from at least 4.4 onward.
Logging the data out from the chip we see it drop the connection and start advertising. About 1 in 10 times, the phone seems to believe that it has a connection with the device, but the logs on the device show that it is still in advertising mode.
Has anyone else ever seen this issue?

Can't disconnect BLE devices when killing the app with background plugin on

I'm developing an app that interfaces with BLE devices using this plugin.
Inside the app, I can pair the devices and monitor their status.
If I close the app I want to disconnect the devices from the smartphone, and when I open it again, I want the app to reconnect automatically to known devices.
Everything works fine without using the background plugin, but I need to use it since the app needs to monitor the BLE devices even when it's in the background.
The problem happens ONLY if I use the background plugin: if I open again the app, the known devices are not reconnected INSIDE the app, but it appears they are already/still connected to the smartphone from the previous time (even if not shown in the Bluetooth devices in the phone settings).
It seems that the Bluetooth connection to known devices isn't really being closed when I kill the app.
It appears like the device is still connected as therefore it doesn't show up when I scan in the app.
I can't reconnect until I close the app, switch off and then on again Bluetooth, and reopen the app.
The steps are very simples:
I open and connect the first time from the phone to the BLE product
Communication is OK, data is sent and received
I close (kill) the application from the smartphone (Without turning off Bluetooth/BLE from smartphone)
I relaunch the application ---> Known device is not reconnected but appears to be somehow still paired with the phone (if I press the pairing button it does not go into pairing mode, that happens if it is already bonded to a phone).
Why this behavior? Looks like something in the background plugin prevents the Bluetooth connection to be closed on app closing. I specify that:
it only occurs using the background plugin, without it activated everything works ok
this behavior occurs only with Android (don't use the background plugin for iOS)
it does happen only on some Android smartphones: tried three different phones, with Android version v4.4, v5.1.1, and v6.0.1, and only two of them show this issue (android version 4.4 on S3 and 6.0.1 on S5 Neo).
Thanks

Android: Can't connect to specific bluetooth device

I have an application that regularly polls BLE peripherals for data. On rare occasions, the Android device is not able to connect to specific devices for long periods of time.
Not only using my application, but with any other BLE-application I could find on Google play, is it unable to connect to one specific peripheral X. It can connect just fine with other ("identical") peripherals during this state, and other Android devices can connect to peripheral X. This problem tend to go away after a couple of hours or days by itself. Restarting the device, and re-enabling WiFi and bluetooth does not solve it.
The Android devices being used is Samsung Galaxy Tab S2.
Is there some kind of hidden blacklist in the Android BLE stack, to which the address of peripheral X was added for some reason?
EDIT: Manually clearing the "Data" and "Cache" of the System application "BluetoothAdvertisements" in "Settings" appears to fix this state, and the device is yet again able to connect to the device. The big question is now, what is causing this problem, and how can one avoid it.

Categories

Resources