Android and bluetooth headset volume - android

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.

Related

Android audio over HSF bluetooth connection using a virtual call

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.

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.

Is it possible to send/receive voice from PC to Android device over Bluetooth

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 ...).

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...

How to force a connection to a a2dp bluetooth device by an activity or service

I'm using my Nexus One with Android 2.2 Froyo in my car dock. For the audio output I'm using a a2dp receiver which is hooked up to my car stereo.
Now, when I put the phone in the car dock it automatically connects to the car dock but not to my a2dp receiver, I have connect it manually in the settings (already paired).
I'm also using a custom app for audio playback. I thougt I maybe could force the a2dp connection to the a2dp receiver. But as far as I know, the default Bluetooth API does not support such a thing.
Is there any Intent for establishing the connection, or any other way? I would also accept an undocumented solution.
I fixed this recently with the app A2DP volume.
My issue was my lg p920 on android 2.3.5 would connect to handsfree and a2dp stereo audio with my Sony car stereo mex bt3950ou (many other brands have the same issue).
Once the car was turned off and back on again ie. in turning the ignition from acc to start, the connection would be lost and only the handsfree would reconnect.
A2DP volume can be configured to force reconnect the stereo audio connection, see instructions on the A2DP volume site.
See your issue with twin BT devices. You can get BT Visor mount systems that do this. The BB version will stream A2DP music from the device AND allow you to take calls. The drawback is it uses FM to get the sound to your headunit so sound quality will be lower than native BT.
The technique is demonstrated in this app: http://code.google.com/p/a2dpvolume/A2DP Volume
Look at service.java and the IADL file.

Categories

Resources