I have a setup with two Android devices: an android phone and a custom hardware running Android 10. The latter acts as a BLE Server, which is discoverable always with the same static MAC address. Also when that custom HW is paired with the phone it has access to phone's contacts and calls history. That HW can also play media (sound) streamed from the phone.
I use RxAndroidBle 1.11.0 library for BLE communication. As soon as I exchange some data via BLE Characteristic I unsubscribe from the RX observable so the library effectively calls: bluetoothGatt.disconnect() then blutetoohGatt.close()
(all those inside the DisconnectOperation class).
My problem is the fact that based on my observations, calling blutetoohGatt.disconnect() disconnects the classic BT profile (PBAP) as well.
Is it an expected behaviour?
I have investigated the code of generic Android P framework and it looks that calling bluetoothGatt.disconnect() -> bluetoothGatt.close() completely disconnects the device described by the given MAC Address:
BluteoothGatt#disconnect()
BlutetoothGatt#close()
BlutetoothGatt#unregisterApp()
I would risk a statement that I have quite unusual BLE use-case scenario where the phone (Central/Client) and the peripheral (custom Android HW/Server) are connected simultaneously via Classic BT profile and via BLE.
I suspect that disconnecting/closing device using its BT MAC address disconnect both profiles, hence the contacts sharing stops working.
Is it possible to disconnect BLE connection only, but not affect the classic BT (SPP/PBAP) connections between the two devices?
After further investigation described on that Github issue
I realised that my custom hardware is equipped with dual-mode BT adapter so it supports classic BT (BR/EDR) and the BLE one.
As soon as I pair an Android phone with the custom hardware via System Settings, classic BT profiles are bonded, but also my GATT Server advertises relevant services using the same MAC address which is used by the BR/EDR. Disconnecting BLE client connection disconnect BD/EDR as well.
What helps in my case is to not start pairing via System Settings, but let the GATT server advertise and let my BLE client app to connect (and trigger pairing) first. As a result I have a BLE connection with server available under "AA:AA:AA:AA:xx", while the classic BT profiles are connected to "BB:BB:BB:BB:yy" interface on the custom hardware.
Now, disconnecting BLE profile does not disconnect the classic one.
I am looking for a solution which would allow my GATT Server to be advertised with BLE only, but no luck so far.
Here are some interesting links I have found:
connectGatt creates connection over BT Classic instead of BLE
how to force BLE "just works" pairing in Android
BLE Dual-Mode
Related
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..
I have a bluetooth hardware device ( embedded one ) that is acting as a client and connecting with pairing permissions automatically to any device whose bluetooth is ON. But it is not connecting to the BT chat application installed on my android phone. The BT chat application works fine when it connects to my hardware device as a slave. But in case of my hardware device acting as a client and BT chat acting as a listening server, connection fails.
Does the AcceptThread code works only on application level and not on system level?
The hardware device connects my android phone at system level but not to bluetooth chat application.
Is there any solution?
Bluetooth chat app basically supports only classic bluetooth.
Please check the bluetooth profile of your embedded device. Does your embedded device supports classic bluetooth?
I suspect your chat application is using createRfcommSocketToServiceRecord().
Use the createInsecureRfcommSocketToServiceRecord instead. Insecure socket allows the RFCOMM to communicate with a non-authenticated paired device. Embedded devices like the RN42 or KC2114 have a difficult time performing authenticated pairing, because user interaction is required (numeric comparison, yes-no response). The "Just Works" automatic pairing will not produce an authenticated pairing. KC2114 supports both automatic authenticated pairing (with a small hack) and Just Works non-authenticated pairing.
I am a little confused on how to build this android app. Here's how it should work. I have a list of paired bluetooth devices. Lets say paired devices are:
1. A bluetooth head set.
2. A mobile phone.
And my app should automatically connect only to my headset when ever it comes in range.
Thats the basic functionality. I have been doing some research on bluetooth technology and its implementation. I came across the bluetooth chat application, when I started using the application I realized that both phones should have the app on it in order to connect and exchange messages. I tried connecting to my headset but it doesnt connect. And also when I removed the bluetooth chat app from one of my device and tried to connect it from a device which had bluetooth chat app, the devices couldnt connect.
If you have already worked on bluetooth this might look very simple. But how can I connect to a bluetooth device from my app when ever its in range even if the other device doesnt have my app.
Thanks.
This will be a 2 sections answer:
-To connect to a Bluetooth Headset, check my answer on here
-To Always connect to that device, you can save device address to memory then create a service with BroadCastReciever that listens for Bluetooth Connectivity. and check which device gets connected and compare it address to the one save in memory once its finds it connected call ibth.connect(device). ibth is inside the above link.
My applications connects my Android phone to a health device. The health device is capable of connecting using either Bluetooth SPP or HDP profile while my app can only support SPP.
The health device's documentation states that I have to send a special command to the it during the pairing process to make sure that Bluetooth communication uses SPP profile instead of HDP.
Note that I'm not concerned about connection after pairing at all. I need to:
Separate the pairing process from the connections after pairing - I don't mind if users have to authorise pairing through a popup
Be able to send some data to the health device during the pairing process (so that following connections will actually happen)
The Android documentation seems to imply that pairing is implicitly handled as an integrated part of the Bluetooth connections as you call connect() or accept(). However, this and this gives me some hope.
I'd like to support as many devices as possible but 4.0 and above are more important. The health device I'm using supports Bluetooth 2.1 so no worries about PIN.
I am trying to use Bluetooth SPP to communicate over it. In some Android phones, SPP profile is not activated. I faced the problem in the application that SPP was not activated and so the connection could not be established over bluetooth and when I started another app that is 3g hotspot which I think activates SPP and I was able to connect over bluetooth in my app.
So, how can we actually activate SPP profile of bluetooth in Android devices? And does all the android devices has SPP profile?
In developer.android.com BluetoothSocket:
The most common type of Bluetooth
socket is RFCOMM, which is the type
supported by the Android APIs. RFCOMM
is a connection-oriented, streaming
transport over Bluetooth. It is also
known as the Serial Port Profile
(SPP).
This might answer your question ..
https://source.android.com/devices/bluetooth/services
SPP (or ability to use Java API's to establish RFCOMM channels) is available from Android (2.0/2.1) release (Eclair) onwards
On the Android phone you will probably need to run an application that initiates the service over SPP.
**
public BluetoothServerSocket
listenUsingRfcommWithServiceRecord
(String name, UUID uuid)
** API can be used to create a service with specified UUID to listen,
Doing this should make this service visible to other devices which can then connect to it.
I just called Samsung help regarding bluetooth SPP on an S8+ phone. They tell me wait for Android Oreo as it isn't available till then. My previous Sony Xperia used Ntrip Client to talk to an external Geneq GPS to receive corrected coordinates and worked really well. Seems we went backwards somewhere?
Ntrip client on the phone collects an internet data stream of GPS corrections every five seconds and sends these to the GPS. The GPS uses the corrections and sends back adjusted coordinates to the phone to use in any application.
I would appreciate someone brighter than me pointing out a quick fix I just load and run to bring back this functionality.