Switch model from BLE to Bluetooth Classic in Android - android

I'm setting up a mobile application to support bluetooth communication between an android phone and one dual-mode bluetooth module. Two devices must init a BLE connection and transfer sound through HandsFree profile. At any time, two device must be able to re-establish these communications.
Should application shut down the Classic bluetooth process after sound transferring is done and always connect by BLE??

If I understood your question correctly, you don't need Bluetooth Low Energy (BLE) for your application. If you just want to transfer sound through the HandsFree profile, then this can be accomplished with classic Bluetooth alone and you can even turn BLE for the entirety of the application.
Please see this Android Developer page which gives a step-by-step guide on how to do this and provide sample code:-
https://developer.android.com/guide/topics/connectivity/bluetooth#Profiles
Finally, please note that for the most part BLE and classic Bluetooth are mutually exclusive; even though they are part of the same specification, they are like two different wireless technologies and in almost all cases your application will need one or the other, but not both. Please see this post for more details:-
Can a Bluetooth LE powered device discover a classic Bluetooth device and vice-versa?
I hope this helps.

Related

Bluetooth connection like wearable devices

I am searching for some way that can connect to Bluetooth devices without pairing. Or at least make a connection first and then it does not need to be established all the time. Like how wearable devices work (i.e. mi band 6 or Huawei band 6). Can someone please guide me towards some helpful demo or documentation for this somewhere?
Also, I was wondering how was the security managed since my Bluetooth is always on to communicate to the wearable device. Though, turning off discoverability does not seem to create any issues in order to communicate with the device.
Most wearables nowadays use Bluetooth Low Energy (BLE), and with BLE you don't need to pair in order to exchange data - i.e. only a connection is needed. That being said, it is recommended to pair as the data exchanged between the wearable device and the phone will be encrypted, in addition to some other benefits in terms of privacy and security, Have a look at the links below that will go over connection/pairing in more detail:-
Should one create a bond with BLE device
The Ultimate Guide to Android Bluetooth Low Energy
Making Android BLE work

Android & Dual mode Bluetooth device: Custom BLE service not found when paired to BR/EDR (Classic)

I've built a dual mode Bluetooth device using the BT 121 from Silicon Labs. The device implements SPP over the classic connection. The device name of the classic node is "XYZ Classic". It also implements a custom service (128-bit UUID) in BLE. The device name of the BLE node is "XYZ_BLE". Both nodes have the same MAC address.
When pairing under 'Bluetooth' settings, sometimes I will see 'XYZ Classic' and sometimes I will see 'XYZ_BLE'. It seems random which one it will pair to but many Android devices I've tested have a tendency to want to pair to the classic node. After pairing, a connection over classic/SPP ALWAYS works. However, I can only connect to the custom service if paired to the BLE node. If paired to classic I can see non-custom BLE services but not my custom service. To summarize:
Function Classic Pairing BLE Pairing
Spp Works Works
Cust BLE Doesn't Work Works
When I pair in code (Android) the problem also happens despite the fact that I search for the devices named 'XYZ_BLE' and then pair to the device returned. I've looked but I can't see a way to force Android to pair to the BLE node.
My only workaround thus far has been to modify my BT 121 firmware to not allow bonding in classic mode. This is not an ideal solution has any Bluetooth Classic only devices will not be able to bond with my device (In reality this might not be too big of a problem but I have one tablet in my possession that only has Bluetooth Classic).
It should be noted that I've used 'BLE Scanner' from the play store to verify that my custom service works/doesn't work depending on the pairing mode. In other words, it's not just my code. :)
So, does anybody have any ideas on how to force Android to pair to the BLE node?
I see similar issues. Some hints:
Android behaviour differs dependent on the bit flags you set in the BLE advertising. There is for example a bit called "no br/edr support" or so. There are also bits telling explicitly that br/edr dual role is supported.
Also ble pairing may be enforced if you access a characteristic which returns a "not authenticated error" from a ble app. At least on iohone, the os will initiate the ble pairing automatically.

How to make a BLE mesh network?

I had been wondering how wireless earbuds work and came across this image. I do not know how to replicate what is shown in the following image and would like to learn how to do it.
My end goal is to be able to have the smartphone connect to a device, while still being able to play music to a Bluetooth Headphone. I read into BLE 4.1 mesh and I am not sure if that would help either.
I have made images for the possible ways the multiple devices could communicate but I don't have enough reputation to attach the xD. I will try my best to describe them.
1) All devices manage to simultaneously communication with the smartphone.
2) All devices connect to a hub which relays data to the smartphone.
3) One device is the hub itself and relays data for all other devices while sending its own data.
4) The devices relay information for each other till the smartphone receives the data it called for.
5) Another possibility is to have a mesh structure where the devices relay all messages broadcast-ed over the network until the device for which the message is meant for, receives it.
I hope to make a project where a Bluetooth device I make does not hinder the user from connecting and using other Bluetooth devices simultaneously.
Thanks for reading and I look forward to any and all responses.
IMAGE 1:
IMAGE 2:
IMAGE 3:
IMAGE 4:
You need to consider few things first.
Since version 4.0 Bluetooth specification contains "Classic
Bluetooth, Bluetooth high speed and Bluetooth low energy (BLE)
protocols."
Bluetooth Classic provides profiles like A2DP, AVRCP that
are usually implemented by Bluetooth earbuds or speakers.
BLE on the other hand communicates using GATT (a general specification for
sending and receiving short pieces of data known as attributes over a
low energy link).
BLE is not designed to handle high bandwidth scenarios like Audio.
Now getting to a point
You can have a smartphone connected to your earbuds with A2DP profile
and simultaneously connected to several BLE devices.
One or more of these BLE devices can realize mesh connectivity

Can a mobile application that is developed to work on Bluetooth technology be used on Bluetooth LE technology?

Can a mobile application that is developed to work on Bluetooth technology be used on Bluetooth LE technology?
Or does the developer need to modify code to handle Bluetooth LE (Smart) signals, input, output etc. ?
EDIT
While i was asking this question i want to know
if i write a code piece, can i run it on BLE devices, also with BLE performance?
Is it possible, or not?
If a device can have both B and BLE then i have one more question:
Should we write code with different APIs for ordinary B and BLE?
I don't know of any phone that is doing BTLE but not classic Bluetooth as well. So the application should still work but it will still just be using the classic Bluetooth portion of the hardware.
Of course from the sensor of other device your talking to point of view the situation may well be different as there are BTLE only sensors for example that may have a similar function to an old style Bluetooth sensor but they want be compatible. E.g. some classic Heart Rate sensors and modern BTLE heart rate sensors.
If you want to connect to only BLE devices(LE profiles) , then you need to definitely modify code as profiles on LE devices are GATT based , unlike Bluetooth Classic.
You will need to implement GATT Client and GATT server in your code.

How to make an Android phone as bluetooth headset

I have 2 Android Phones, and I want to connect them together via bluetooth, and make one of them a bluetooth headset.
So, my question is how to program the second phone to change its role profile to "Bluetooth Headset" when establishing the connection ?
I've found this post but my question is a little bit different
Thank for any advice or idea :)
You cannot on Android. At least using the built-in Bluetooth A2DP profile.
Your phone will only act as a transmitter (source), not a receiver (sink).
Please look at these two answers I gave on why this is not possible :
Is it possible to send/receive voice from PC to Android device over Bluetooth
Receive audio via Bluetooth in Android
You can, on the other hand, develop two apps each acting as a client/server using your own protocol. The server could be streaming audio content to the client via Bluetooth for instance.
Another way to consider this, since using an Android device as an A2DP sink is not feasible on every phone, is building these two apps using your wifi connection. It could be much more rapid and the sound sound be of a much better quality.

Categories

Resources