Android BLE disconnects after bonding - android

I'm developing 2 Android BLE applications. One app will serve as the peripheral role and the other app will serve as the central role. On the peripheral app, there is one encrypted characteristic with PROPERTY_WRITE and PERMISSION_WRITE_ENCRYPTED.
The central app is able to connect to the peripheral and discover its services. The first time that central attempts to write to the encrypted characteristic, the system begins the bonding process and a dialog for entering the PIN appears. After the PIN is entered correctly, the characteristic can be written to successfully. If the central disconnects from the peripheral and then attempts to reconnect, a connection is briefly established but then disconnected. The onConnectionStateChange callback is received on the peripheral with a status of STATE_CONNECTED and then immediately called again with a status of STATE_DISCONNECTED.
Unless I manually unpair the devices (from the Bluetooth settings) and then start the connection process again, the central is unable to connect to the peripheral.
I've tried this solution but it did not work for me.
BLE Device Bonding Remove Automatically in Android
Both apps are running on devices with Android 5.

This issue seems to be resolved in Android 5.1.1. Originally, I was running the peripheral app on a Samsung Galaxy Tab A with Android 5.0.2. I switched to a Nexus 9 running 5.1.1 and 6.0.1 and did not encounter the issue described above.

Related

Android 5.x BLE GATT service not discovered, but device is connected

My BLE discovery and connecting is working fine on Android 6.0 and higher. However, on version 5.x devices (both are Samsung - Note 4 and Galaxy Core Prime) I am able to scan, find my peripheral, connect and get the onConnectionStateChange callback. All the connection steps work fine.
After onConnectionStateChange I call gatt.discoverServices() - this returns onServicesDiscovered() and then I call getSupportedGattServices(). getSupportedGattServices() returns successfully but it's missing the specific Service UUID that is on my peripheral. I know the UUID is there because I can see it on the peripheral and my other Android devices can connect to it. I'm logging all the discovered UUIDs and it only sees the Generic Attribute Profile and the Generic Access Profile services.
I checked the ScanResult class returned in LeScanCallback and the service UUID is there. And again, this is only happening on 5.x. 6.0+ Android devices discover the service without issue.
Thanks.

Android (Things) GATT server stops advertising

I'm developing an Android Things app (Dev Preview 6.1, Raspberry Pi) with a GATT server. When a connected client app disconnects, my device has stopped advertising. However, the custom client app (out of my control) is written in such a way that it needs to disconnect between reads/writes, then reconnect.
I know that I can restart advertising upon disconnect, but since it has a new (pseudo-)MAC address, the client can't automatically reconnect.
FWIW, I see the same behavior in this sample (& using nRF Connect as a test clinet): https://github.com/androidthings/sample-bluetooth-le-gattserver
Is there way to keep the GATT server advertising in this case? Or can I specify the advertised device address so that I can keep it consistent across advertisements?
It turns out this is a known bug in Android Things: https://issuetracker.google.com/issues/70269277

BLE connectivity not consistent on Samsung devices

We are using Android BLE code for connection to a custom hardware and with most mobile devices, this works perfectly. However, when it comes to Samsung with the Android OS Version 6.0.1, attempt for connection is not successful in most cases.
The problem is happening after trying to connect to a device with bluetoothDevice.connectGatt(context, false, gattCallback);
In onConnectionStateChange callback gatt status code 133 is received and in that case what the app does is to close the current instance of the BluetoothGatt and connect again to the device for a new BluetoothGatt instance. This workaround helps to get a connection after a couple of retries but this is definitely not the way how it should work.
After doing some BLE sniffing, it is clear that the device is not even trying to connect to the peripheral and just gives out the general gatt error (133). What is interesting that this has been a major problem only for the Marshmallow update, more specifically on the Android 6.0.1.
So my question is whether anybody experienced similar connectivity issues with only selected devices, where the mobile device tries to connect to the device and instead receives 133 gatt status code?

Android Bluetooth Low Energy peripheral - Connection loss after bonding

I am implementing Bluetooth Low Energy's HID over GATT (HOGP) profile on Android Lollipop. My target is to use the phone as a keyboard/mouse, which can just plug and play with the default BLE (HID) drivers in Windows 8.1 laptop. The Android phone is supposed to act as BLE peripheral and the laptop should be in BLE central role.
Currently, I am able to establish a very short connection with the laptop. But just right after I enter the passkeys, and bonded successfully with the laptop, the BLE connection will be lost. Have anyone faced this kind of problems before? Or have any solutions on it?
Also, I failed to add generic access service to the gatt server in Android. I am curious if GAP service is included in Android BLE communication by nature? The reason I want to include this service is for defining the "device name", "appearance", and the "peripheral connection parameter update" characteristics. How I can do so?
Did you get your system fixed, I am seeing something kind of similar, where after bonding, my device will go to paired list, then about 20 sec later, the bluetooth on /off button will automatically switch to off position, wait 10 sec, then back
to on position, and my device is gone..

android BluetoothGattServer disconnects after some time

Maybe someone have some experience with new Android Lollipop Bluetooth API where device can play a peripheral role.After I opened a server and started advertising service with characteristics some central device connects to my device,read my data,but than for some reason Gatt server disconnects.Any ideas why this might happen?It is repeated with both iOS and Android device as centrals

Categories

Resources