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.
Related
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.
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
I made a research on the same topic and found that android devices are a2dp sources and the audio can be streamed only from an a2dp source to an a2dp sink. A2dp sink can be a bluetooth headset or a bluetooth speaker.
But my question is then how the android app named "Bluetooth Music Player" works?
It allows streaming from one mobile to another. So in this case the listening mobile device must act as a sink. How this is possible?
Are they using some other profile instead of a2dp?
Ok, that may be a different profile what they are using. Because the application needs to be installed in the client side also.
But how it becomes possible to stream voice from a bluetooth microphone to an android device?
Please help.
Without knowing details about the mentioned Bluetooth Music Player, it seems to use simple Bluetooth data connection, otherwise you would not need to install a client on playing/sending device.
To stream audio from microphone to another device, you can record it on your sending device and send it to the receiving device. You will need to implement a protocol for that purpose.
OR
You can implement an alternative A2DP sink service. This is, what the sink is: a device with a Bluetooth Protocol Stack with an implementation of A2DP Sink.
Edit:
For the case you detailed by your comments, the sending device should be left as-is, without installing any app. That implicitly means that your solution must make use of out-of-the-box Bluetooth functionality of that Android device.
What you can use here is therefor limited to those profiles that Android typically support, which is HSP, HFP and A2DP. Since you obviously want to stream music, A2DP would be your choice.
On the device supposed to receive the audio stream and do the playback, you have to implement a service providing the A2DP sink as an self implemented BluetoothService opening a BluetoothServerSocket on RFCOMM as described in Android documentation.
You will have to spend much effort implementing this, and I am not sure if you will need a license for this.
I want to make my android device working as a bluetooth headset.
I search the Android APIs, but I just find some interface which
can make Android device working as a masters, not as a device(bluetooth headset).
I'm also ready to modify the source codes of Android OS, and rebuild the OS.
What I hope is, when Android devices connect to a mobile phone with bluetooth, the Android devices can work as a bluetooth headset.
I don't know whether there are interfaces can do this, or I should modify the Android OS?
Thank you!
You need to implement HFP profile in your android device, normally phone role is AG(Audio gateway) and headset roles is HF(Hands free) , think its as a server and client role. Connect RFCOMM channel to phone using UUID defined for HF , have SDP record updated,changes will be required to handle AT Commands as well.
These will be the initial changes, once done you will need to handle audio packets(SCO packets) for voice calls
I have a PC (where java program is running), Bluetooth dongle (which supports A2DP) and Android device (2.3.6, which also supports A2DP).
I want to:
Send real time voice data from PC's microphone to android device via bluetooth
Send real time voice data from Android device's microphone to PC via bluetooth
I found this question, where Dennis says that "Phones are typically only Source devices (Source of the stream that can stream to sink devices), Sinks are Headsets or Bluetooth speakers.". So it seems it is possible to implement case 2? Or not? And what about case 1, is it impossible to implement?
It is true that Android phone are uniquely A2DP source devices.
Sadly, your first case is impossible to realize if you decide to rely on the A2DP profile for streaming audio, because Android does not implement the required callbacks supposed to be handling BlueZ's advertisings when a remote device wants to stream audio to your phone.
The second use case is possible, given that you have a bluetooth enabled PC and some awesome apps that will decode and route the sound from the Bluetooth stack to the speakers. I managed once to reproduce this use case using PulseAudio and pulseaudio-module-bluetooth on Ubuntu 12.10.
Here is a working example showing how to manage the routing of the sound once a connected BT device begins to stream. Here is another one. They both take place on Linux and I never did this on Windows though.
For the sake of completeness, here is another SO answer written by me, giving details about how to implement A2DP sink capabilities on Android.
EDIT :
Nothing forbids you to implement your own protocol for audio streaming via Bluetooth on an Android device, this will work, but as it will not be a standard, it will never comply with the system built-in Bluetooth profiles (A2DP, HFP ...).