Turn Android phone into Bluetooth headset - android

Let's assume we have a rooted Android OS on a device that supports Bluetooth. Can we build an app that advertises itself as a Bluetooth speaker via Bluetooth A2DP?
If that was possible, then any other device could pair / connect to our Bluetooth server app and stream any music / sound. This server app could then take the music stream and play it locally or even send it to other devices via Wi-Fi. This would theoretically enable a multi-room Bluetooth solution.
Any idea how to achieve this? Where would I start?

Turns out there is a very good and detailed answer to a related question here.
Short Answer: Possible, but requires to modify the Android OS configuration and quite some low level NDK development to expose the A2DP Sink role as API to be used.
Thanks #BartPlatak for the pointer!

Related

Use Linux as a microphone for mobile phones. Proxy voice over Bluetooth or USB

I am looking for a way to turn my pc into a microphone (wireless or USB) to send voice to the connected mobile device (ios and android).
I couldn't find any information regarding of possibility doing so and my knowledge of Bluetooth protocol is pretty bad so before diving deep into it I would like to know if it's even possible.
My thoughts were to use the PulseAudio-Bluetooth module to transfer voice but is it possible to make my Linux be discoverable as a microphone with it?

need idea on sending/receiveing audio over A2DP between android/non-android device

I need to be able to send and receive audio over bluetooth and it seems A2DP is the thing that does this
Using the code given here, I managed to get my phone to detect and pair with the remote bluetooth device, then establish an A2DP connection which sent all the audio output of the android device to the remote one via bluetooth
I was previously able to do such two way data communication with the same remote bluetooth device via RFCOMM (the android phone needed to be the one initiating the communication though, I could not do it through the remote device though I know it is possible). Once the RFCOMM link was established, the android device could send data to the remote device, as well as receive data from it
What I need now is something similar, but for audio (preferrably using A2DP, but I am open to using whatever else, as long as it gets the job done). While snooping around SO I've got hints that receiving audio data on phone (at least an unrooted normal one, rooting is not an option for me) via A2DP is not possible (see for example, here). But I have also seen headsets that allow making phone calls entirely through bluetooth (well, wirelessly actually, I am assuming it must be bluetooth). For example, for an incoming call, you can just press a button on the bluetooth earpiece, then you can talk as well as listen to the other party. If a phone cannot be used as an audio sink, how do such headsets do it?
I need some ideas on how I should go about writing an android app to send as well as receive audio data via bluetooth (for simplicity lets consider it similar to the Bluechat sample program, but involving audio instead of text). Is it possible at all (through java)? Is it possible only through NDK? How do the devices on the market do it? Is it a different profile than A2DP?
PS: My test devices are Samsung Galaxy 2 (phone) with Gingerbread and Asus Nexus 7 (tablet) with KitKat. Incidentally the remote bluetooth device (it is a development board) comes with a sample project that is supposed to turn the board into an A2DP audio source. if I run this sample project on the board, using the phone's and tablet's built-in bluetooth settings, I can sort of pair with the remote board, but the android devices do not receive any audio.
There are two different A2DP profiles, A2DP source and A2DP sink. The A2DP source profile is supported by Android thus allowing you to stream music from your device to a sink like a bluetooth speaker. To my knowledge the A2DP sink profile is not enabled, which is why you're unable to stream music to your mobile phone and have it act as a speaker. I only know this from having googled around some time ago so things may have changed.
It is possible to enable the A2DP sink profile by editing /etc/bluetooth/audio.conf and rebooting your phone. Unfortunately this has the side-effect of disabling the A2DP source profile and thus cannot be used in a widely distributed app. The other downside is that there is not much of a java software stack for working with that profile so you'd have to do quite a bit of work to get things rolling.
To answer your question as to why a headset is able to connect to the Android, that is because headsets use a different profile called Headset profile (HSP), commonly used by headsets, or Handsfree profile (HFP) commonly used in cars. Both profiles have two sides: a client side and the gateway side (mobile phone). The audio quality of both of these profiles is considered voice quality. 8 or 16kHz sample rates and a crappy codec. There is also a lot of protocol for answering/making calls, etc... I'm not sure if you'd even get audio to transmit without an active connection to the phone network.
For A2DP Sink support -
Yes. It is possible. I have done it in Android JB.
Android device as a receiver for A2DP profile - Please read my reply.

How Do I Stream Audio Into An Android Device?

I need to play a sound received wirelessly (Bluetooth or Wi-Fi) from a device (Android, iPhone, PC, ETC) to an Android device (Running Android JB 4.2.2), i think it will be almost impossible using bluetooth because the replacement of BlueZ with Bluedroid (which does not support A2DP Sink profile).
How can i connect both devices and make the streaming?
Have anyone a project like that, or have a link where it's something similar?
Please help me find out how to do it, thanks for all.
Alljoyn uses multiple transport layer and has many core services for data transfer between devices, it claims support for bluetooth but as now bluedroid is available, alljoyn can help you out with wi-fi, go through alljoyn audio service

How to Stream Audio from PC through Bluetooth

Here's what I am trying to do. Capture any audio being currently played on the PC and stream it through Bluetooth and then play it through the Android device paired with the PC. I have worked with Bluetooth a little but very basic stuffs. And I have very less idea on how to go about on this. My target device is Android 2.2 (and above). I guess I have to use Bluetooth profiles, but not too sure. Also, I am not aware of any other caveats that I may have to face.
Would anyone like to point me at the correct direction. Any tips, links would help. Thank You.
It depends on the capability / profile that your android device supports, for streaming you normally will use the A2DP profile and the android device will need to support the A2DP sink role. Typically this role is supported by Stereo headsets , speakers etc. Android phones do not support sink - phones are A2DP source (or initiator of the streaming)

Bluetooth A2DP profile

I am completely new to bluetooth app development. what exactly is a bluetooth profile? is it a hardware specification for the device? can an android mobile phone with bluetooth act as sender and receiver in A2DP profile?
A bluetooth profile is a specification on the protocol and functionality of a bluetooth device. It is not just a hardware specification, because implementing a profile will often depend on both the software stack and the hardware chip. You can find more information from the wikipedia page.
And in the case of A2DP, it is specifically designed for music streaming. It cannot be used for arbitrary data communication (if that's what you mean by "sender and receiver"). If you are looking for a generic data communication mechanism over bluetooth transport, the Serial Port Profile (SPP) is what you need (some people also call it RFCOMM). Android SDK user guide has quite detailed information on how to use RFCOMM API: http://developer.android.com/guide/topics/wireless/bluetooth.html
There are two A2DP profiles: A2DP source (the device that sends audio) and A2DP Sink (the device that receives and plays the audio) like a Bluetooth headset.
Your phone hardware supports both profiles, but A2DP Sink isn't implemented in Android so you cant just write an app to use it. You need to modify Android source code and build your own ROM.
If you want to do so you need a device with an available source code (a Nexus or a device supported by CyanogenMod).
If you use Android 5 or up it wont be very hard to enable the A2DP Sink as it's already included in the source but disabled.
If you use Android 4.2 -4.4 you need to port the A2DP Sink classes from Android 5.
As for Android prior to 4.2 things are different as they used a different Bluetooth stack called BlueZ (now they use Bluedroid) you can activate A2DP Sink by rooting your device and editing "audio.conf" file but unfortunately even though your phone will be advertising itself as a A2DP Sink you will hear no sound as it's not routed to speakers and to route it you will have to build a modified ROM.
Building a ROM might seem complicated but it is not, specially if you're using Android 5 or up as, like i said before, the SINK profile is already there all you need to do is type 6 lines in the terminal (you need a Linux OS) and edit 3 lines of code to enable the A2SP Sink and build your own ROM.
If you are interested in this I can give more details.

Categories

Resources