Android audio over HSF bluetooth connection using a virtual call - android

I'm trying to send audio over my cars speakers without having the cars audio input set to bluetooth. It supports the A2DP profile, and I also managed to get it to work. But that only works when I manually set the input to Bluetooth.
But I would like to 'force' the audio being sent over the speakers.
I previously had an iPhone. The Google Maps app would 'call' itself everything it would pronounce the directions. So my car would see it is an incoming call and play the audio over the speakers.
I looked around the internet, and it seems I need to use the HSF profile to pull of the same trick.
The documentation states that HSF is supported, but it does not show me how to do it. I also found exactly what I needed in the documentation. It states the following:
NOTE: up to and including API version JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO audio connection is established.
So initiating virtual voice calls was possible. I would like to know how to do that now. Any other ideas on how to do this would also be very helpfull.

Related

How get the current device audio stream routing on Android?

Due to some deprecated API, I'm looking for code to know which device is routing current audio Stream. I can list all devices, know if the headset is connected but the API says connected but not routing. Now, I want to check, how to check which one is routing audio at this time.
I found in documentation but don't know how to use: https://developer.android.com/reference/android/media/AudioRouting.html
Any ideas?

Chrome web audio api - how to play sound in a phone call

I cant find anything online but how can i use a chrome tab web audio api in an android app so i can play sound during a phone call.
i went to this site but when i play the sound during a phone call the far end doens't here anything. I thought one feature of web audio was that it can play change the sound of someones voice in a phone call, so i thought it had access to the audio phone call stream.
even here the tech says its ready for android but i cant even get hte audio recorder demo to work on android.
While you do (with the user permission) have access to the input of the device you only have access to the main output of the device (internal speakers or headphones). This is represented as the AudioContext.destination. The buffers in a call is (probably) a different output that you simply don't have access to in Web Audio (and that's probably a good thing. Imagine the security issues we'd have if apps were allowed to hijack calls!).

Bluetooth audio streaming between android devices

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.

How call process works with blue tooth devices?

I tested few things on Android mobiles with bluetooth headset.I have few questions regarding the same.
Device Specifications :
Android 2.3 above
Headset Blue tooth profiles : HFP,A2DP
I accepted a call from accept button from the android mobile and I was able to hear the call from the bluetooth headset.After that I moved android device out of range and accepted the call from android and when the android mobile entered bluetooth range bluetooth headset connected automatically.Is it universal, I mean all the bluetooth headsets support the same or are there any deviations?
I would like to know what will happen when we accept the call from headset or Android mobile.Is it something like Android OS is going to create a call session/audio session and transfer this to headset when accept button is pressed from the headset.If a call is already received and when the headset is in bluetooth range,Android mobile is going to route the volume to headset. In both the cases the same thing happens(just routing the audio).I would like to know the call handling in detail both the cases.Could some one help me on this.
How the call process is different in iOS?
Edit
Is any call session like AVAudoioSession is getting created when we accept a call ?
#jjv360:
"An app can manually assign a route even though a bluetooth headset is connected, in which case it's up to the app to handle what happens when a new route is detected..."
Is it possible to route the call session to headset(from microphone to headset sco) in an iOS app?Could you please give some pointers on this.
On iOS if you connect a bluetooth headset while an audio session is active the current audio app(s) get notified and by default will transfer the session's route to the headset. An app can manually assign a route even though a bluetooth headset is connected, in which case it's up to the app to handle what happens when a new route is detected...
Also, AFAIK the reconnect is attempted by both the device (for a very short time) and the headsets, so it's mainly up to the headset to attempt reconnecting when it goes out of range. Almost all headsets should do this though.
It doesn't matter which button was used to accept the call (on device or on headset), if the bluetooth headset is connected it will be used, unless an app has specified that it doesn't want to use that route.
The call process AFAIK is the same for Android and iOS.
With the protocol used, A2DP is the high-quality protocol used when listening to music. It supports high-quality audio, but is one-way, so only works if the bluetooth headset is not recording from the mic. HFP is used when recording is also needed, but the quality is less. That is why you will notice on iOS if you're listening to music on bluetooth headset and then start a recording app, the sound quality will become worse until you stop the recording...

Android and bluetooth headset volume

My problem is - how to set up bluetooth incall audio volume.
Since there some apps for this, no one of them works.
Anyway - no app - create one for yourself. I'm very begginer in android development, so i've tried use audioManager.setStreamVolume(), but without any luck - only internal audio has changed after this.
Even playing with startBluetoothSCO() wasn't the answer.
After looking in logcat, how os responds to pressing volume keys, i found out, that after startBluetoothSCO() volume keys in my phone sends AT commands instead of mangling streams (AT+VGM=0...15).
So my code should look something like this:
AudioManager audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
audioManager.startBluetoothSco();
// send AT commands
audioManager.stopBluetoothSco();
Crawling thru web provide me answer that there's no way to directly access modem (and propably other comm ports) from Android API.
So, maybe someone has any goddamn idea how to prevent resetting BT volume on each connect/disconnect to headset? Using code that i could use by myself, or using some 3-rd party app that is available somewhere.
OS: GB 2.3.4, SGS
Thanks for any ideas.
You can send AT commands via RFCOMM connection. But you must do this before the Android has created Headset/Handsfree Profile connection (Called Phone audio in bluetooth settings menu), or at least disconnect the HSP/HFP then connect via RFCOMM on either of the two (Both HSP and HFP should work with unsolicited +VGS commands), set the volume, and then reconnect.

Categories

Resources