Send and Receive data simultaneously via Bluetooth in Android
Indeed you can however bluetooth communication is wide there is BLE which is from bluetooth 4 and communication is absolutely diferent from the normal earlier bt .i would suggest you take a look at bluetoothchat https://github.com/googlearchive/android-BluetoothChat there is plenty of code to communicate on bt<4 and for BLE check https://github.com/hoyuisun/iGaDs/tree/master/Tibbo_android
Android device as a receiver for A2DP profile
Since Android L the BlueDriod stack does support A2DP sink, but it is disabled by default.
To enable it do the following:
/* Enable bluetooth av sink. */
#define BTA_AV_SINK_INCLUDED TRUE
in /external/bluetooth/bluedroid/include/bt_target.h.
This enables sink support in the bluetooth stack.
Also you have to do this change:
<!-- Enable sink support. -->
<bool name="profile_supported_a2dp_sink">true</bool>
in /packages/apps/Bluetooth/res/values/config.xml. This enables the particular UI.
Now you can pair your devices and start streaming. Unfortunately you will hear no sound although you'll receive the packets. The reason is that there is no audio route for A2DP sink. In the commit message of this patch https://android-review.googlesource.com/#/c/98161/ you can find a sample implementation on how to fix this.
Here is a list of these changes:
- https://android-review.googlesource.com/#/c/97832/
- https://android-review.googlesource.com/#/c/97853/
- https://android-review.googlesource.com/#/c/97833/
- https://android-review.googlesource.com/#/c/98130/
- https://android-review.googlesource.com/#/c/98131/
Stream and Play audio from android application to any available Speaker like A2DP,Car speakers etc
i refer u this link please try this
Android: Playing sound over Sco Bluetooth headset
TTS output always going to A2DP
i thing this link can help u
Is it possible to send/receive voice from PC to Android device over Bluetooth
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 ...).
Streaming audio between external bluetooth device and Android phone
I've been able to achieve what I wanted using RFCOMM-based SPP. In order to send audio to the external device, I use the AudioRecord API to record PCM-16 audio to stream audio realtime over Bluetooth. In order to receive audio, I spawn a thread that is responsible for outputting audio to the speaker using the AudioTrack API (in streaming mode)
Bluetooth audio streaming between android devices
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.
Is it possible to receive audio from microphone over Bluetooth and play it from device?
As you mentioned, Classic BT allows bidirectional conversation.
I have not tried this way but of-course you can try changing in-built Audio profile at time you need.
Please give it a hit and let me know in case it works for you.
Cheers!
Vivek
need idea on sending/receiveing audio over A2DP between android/non-android device
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.
Related Topics
Open Google Maps Through Intent for Specific Location in Android
Listview: Textview with Linkmovementmethod Makes List Item Unclickable
Firebase Servervalue.Timestamp in Java Data Models Objects
Sqlitedatabase Close() Function Causing Nullpointerexception When Multiple Threads
How to Add a Bullet Symbol in Textview
Placeholder Text for an Input Type="Number" Does Not Show in Webkit Ics
Acceleration from Device's Coordinate System into Absolute Coordinate System
Android Custom Url to Open App Like in iOS
Android Dialog: Removing Title Bar
How to Listen for a Custom Uri
Pcm -> Aac (Encoder) -> Pcm(Decoder) in Real-Time with Correct Optimization
Recyclerview with Multiple Countdown Timers Causes Flickering
Captured Photo Orientation Is Changing in Android
Android - Expandable Textview with Animation