How to make Android phone as a bluetooth headset?
Asked Answered
Q

2

21

Yes, I know Android has already implemented the Bluetooth Headset Profile, but it is in Audio Gateway Role, not in HeadSet Role.

What I want to do is develop an application on Android phone which will act as a bluetooth headset, so it can connect to my laptop by bluetooth. When I try to call somebody, I can use my phone to dial him, and my application will forward the voice through bluetooth to my laptop, and one other application running on laptop will get the voice data and forward them to Skype or GTalk or some VoIP program else.

In other words, how can I implement the Headset Profile in Headset Role on Android phone? Thanks in advance!

Quaint answered 2/7, 2010 at 5:36 Comment(2)
I to want similar funcationality. i wish to make calls from the pc have audio (VOICE_DOWNLINK) sent back to the pc as a speaker phone. but keep the mic at the phoneIdiographic
This is not a trivial request; in bluez at a minumum you would need to a) add hands-free role to SDP record. b) Remove audio gateway from SDP record. c) Change phones class of device to mimic a headset. This is just to connect over the hands-free profile. As far as sending the audio, etc., that is another challenge. Im not sure that bluedroid even has support for this;you might need a custom kernel.Metalloid
B
4

From the android side, I think the best solution is to open the connection to the service in your computer:

URL url = new URL("http://192.186.0.1/path/to/service");
URLConnection connection = url.openConnection();

Get it as an OutputStream:

OutputStream out = new BufferedStream(connection.getOutputStream());

and then use a AudioRecord to send though the recorded data:

public static final int DEFAULT_SAMPLE_RATE = 8000; 
private static final int DEFAULT_BUFFER_SIZE = 4096; 
private static final int CALLBACK_PERIOD = 4000;

AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 
            DEFAULT_SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, 
            AudioFormat.ENCODING_DEFAULT, DEFAULT_BUFFER_SIZE);
recorder.setPositionNotificationPeriod(CALLBACK_PERIOD);

int bytesRead = 0;
ByteBuffer buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE);
while ((bytesRead = recorder.read(buffer, DEFAULT_BUFFER_SIZE)) > 0) {
    out.write(buffer.array(), 0, bytesRead);
}

All this should be done on a separate thread of course to avoid crashing the app and a mechanism to handle when the recording stops or the connection is lost. Also, I'm pretty sure it should work over wifi although I am not sure if it will be the same with bluetooth (although most devices with BT have wifi now a days and you get more bandwidth)

I haven't tested this code so I'm not 100% sure it will work.

The next thing will be on the machine to transfer the audio into the desire app, but that's above my experience. I imagine you will have to do a virtual driver or something like that. Also will have to do the inverse mechanism for the audio sent from the desktop app into the phone (I'm rather interested on that part since would make a nice wireless headset for watching movies as well).

Here are my 2 cents; I am eager to know if it works. ;)

Bryophyte answered 30/9, 2011 at 10:9 Comment(1)
Recording audio stream from phone line during voice call is blocked on most Android phones on firmware/driver level. You could use custom kernel to unlock such functionality on some phones.Weir
S
1

I don't know if i understood the real question or your main goal... but I had posted here how receive and send the sound from your headset via bluetooth in android.

I hope to help you...

Sip answered 1/6, 2013 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.