Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have android app. I use BLE(Bluetooth low energy) for connect to devices. It is work good, but I have issue on Android 10. This is my code:
Hashtable<String, BluetoothDevice> myHtDevices;
BluetoothGatt gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback);
in onConnectionStateChange I get:
//public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState){
status= 133,
newStatus =0,
I have this issue only Android Q.
I tried this method(add param TRANSPORT_LE), but it not work:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q){
gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback,
BluetoothDevice.TRANSPORT_LE);
else {
gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback);
Add info:
I get myHtDevices by performing a BLE scan.
I callback come immediately.
Device- Samsung 9
This is nRF Connect log:
nRF Connect, 2020-03-24
Device (50:8C:B1:52:B7:8D)
V 19:37:26.248 Connecting to 50:8C:B1:52:B7:8D...
D 19:37:26.248 gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D 19:37:26.549 [Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D 19:37:26.721 [Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I 19:37:26.721 Connected to 50:8C:B1:52:B7:8D
V 19:37:26.745 Discovering services...
D 19:37:26.745 gatt.discoverServices()
I 19:37:26.872 Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D 19:37:27.768 [Callback] Services discovered with status: 0
I 19:37:27.768 Services discovered
V 19:37:27.814 Generic Access (0x1800)
- Device Name [R] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Privacy Flag [R W] (0x2A02)
- Reconnection Address [W] (0x2A03)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
Generic Attribute (0x1801)
- Service Changed [I] (0x2A05)
Client Characteristic Configuration (0x2902)
Device Information (0x180A)
- System ID [R] (0x2A23)
- Model Number String [R] (0x2A24)
- Serial Number String [R] (0x2A25)
- Firmware Revision String [R] (0x2A26)
- Hardware Revision String [R] (0x2A27)
- Software Revision String [R] (0x2A28)
- Manufacturer Name String [R] (0x2A29)
- IEEE 11073-20601 Regulatory Certification Data List [R] (0x2A2A)
- PnP ID [R] (0x2A50)
Unknown Service (6d95c372-02f0-4360-b0c0-432109c2b715)
- Unknown Characteristic [R W WNR] (105998c0-5e55-4de3-9fc9-1cf857231477)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (4f294974-26c0-43f6-aff9-aac109231e0d)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (51bb9208-7ed1-4c10-821a-be0ca1880c36)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (1767ac17-5aac-4692-93b0-1cb11b28fda6)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (3242c75b-0ce2-4560-9cc4-5190b2ee93d3)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (ad2192c7-c2d0-4c2a-b705-194602bf3c9e)
Characteristic User Description (0x2901)
Unknown Service (18b794e2-9679-4676-93e1-6a244758002d)
- Unknown Characteristic [R W WNR] (b8fe10c6-eba1-425d-849c-189e60f4dbc9)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (fd8c491c-e597-4e85-b831-5b4c37a3afc6)
Characteristic User Description (0x2901)
Unknown Service (bd31f74c-7f33-4b27-a2cf-6660b8d1efc2)
- Unknown Characteristic [R W WNR] (e91ed239-2e78-4aa9-8f5a-9701ecac4740)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (6e143748-ac59-4522-bdd0-46fd3e2101d7)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (b1e20318-8afc-47e3-3ac2-1eea626ce7a9)
Characteristic User Description (0x2901)
Unknown Service (baefe645-2991-4f24-9fb1-a8ea687c395a)
- Unknown Characteristic [R W WNR] (898542a6-55e6-4188-ac49-261d3e179640)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (06dc3129-99e3-45e6-8694-8845ce52fdda)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (d49aeb6d-a33c-4cf0-a06f-f7eca72bfe4f)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (583205af-5509-42ed-bdac-f95bb5c7bca3)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (fa54cb0c-ca4f-405d-b8e0-cf3c7d2f5ffe)
Characteristic User Description (0x2901)
- Unknown Characteristic [R W WNR] (b1e20318-8afc-47e3-a32c-e1ae26c67e9a)
Characteristic User Description (0x2901)
D 19:37:27.815 gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
I 19:37:27.840 Connection parameters updated (interval: 48.75ms, latency: 0, timeout: 5000ms)
Any advices?
–
–
–
–
As seen in the AOSP constants, this error is the most generic error you can get. Generally, it happens when the device is out of range but you tried to connect anyway. You should check the full logcat & dmesg to find out the root cause. My BLE app fails to connect to any devices on Huawei phones running custom ROMs, so make sure that the device is on the OEM stock version of Android 10 - and if that doesn't work, try on AOSP instead - you never know what a manufacturer put in their skin.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.