Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Android phone as a bluetooth headset?

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!

like image 705
ET Worker Avatar asked Jul 02 '10 05:07

ET Worker


People also ask

Can you use your phone as a bluetooth headset?

Is it possible to use a cell phone as a Bluetooth headset? No. The following roles are defined for this profile: Audio Gateway (AG) – This is the device that is the gateway of the audio, both for input and output.

How can I use my phone as a bluetooth headset as a microphone?

Use Lesser Audio Switch (play store) . Plug in earphones -> Go to the settings of this app -> enable switch microphone ->tap the mic icon in front of speaker icon ->select 'internal microphone' -> enjoy!!


2 Answers

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

like image 199
pablisco Avatar answered Oct 18 '22 03:10

pablisco


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

like image 20
SerSánGal Avatar answered Oct 18 '22 02:10

SerSánGal