Hi guys,
I am trying to make a Java program that allows my PC to become a headset for my cell phone so that I can pick up/dial out calls from my PC and talk using speakers and mic of my PC, in other words making my PC a headset for my cell phone. I know that this can be done by simply going into my mobile phone and choose to find "Headset device" and pair my phone with my PC. However as a developer I would like to know how this can be done in Java.
I am currently using the BlueCove stack and NetBeans to do this project. I did the Device Inquiry and Service Discovery processes fine but when I try to establish a connection with my phone everything seem to fall apart. Here is the client connection portion of my project:
import java.io.*;
import javax.bluetooth.*;
import javax.microedition.io.*;
public class BluetoothClient {
public static void main(String argv[]) {
ServiceBrowser SB = new ServiceBrowser();
BufferedReader READ_INPUT = new BufferedReader(new InputStreamReader(System.in));
SB.main(null);
try {
String _handsFreeURL = "btspp://001EDC79EA26:5;authenticate=false;encrypt=false;master=false";
String _headsetURL = "btspp://001EDC79EA26:4;authenticate=false;encrypt=false;master=false";
String _dialUpURL = "btspp://001EDC79EA26:1;authenticate=false;encrypt=false;master=false";
String _serialPortURL = "btspp://001EDC79EA26:2;authenticate=false;encrypt=false;master=false";
StreamConnection HEADSET_CON = (StreamConnection) Connector.open(_headsetURL);
OutputStream HEADSET_OS = HEADSET_CON.openOutputStream();
InputStream HEADSET_IS = HEADSET_CON.openInputStream();
StreamConnection HANDSFREE_CON = (StreamConnection) Connector.open(_handsFreeURL);
OutputStream HANDSFREE_OS = HANDSFREE_CON.openOutputStream();
InputStream HANDSFREE_IS = HANDSFREE_CON.openInputStream();
String _command = null;
while (true) {
System.out.print("Enter command here: ");
_command = READ_INPUT.readLine();
if (_command.compareTo("end") == 0) {
break;
} else {
// Send output //
HEADSET_OS.write((_command + "\r").getBytes());
HEADSET_OS.flush();
// Read input //
byte _buffer[] = new byte[80];
int _bytesRead = HEADSET_IS.read(_buffer);
String _received = new String(_buffer, 0, _bytesRead);
System.out.println("Received from mobile: " + _received);
}
}
HEADSET_CON.close();
HANDSFREE_CON.close();
} catch (IOException CANNOT_START_CLIENT) {
System.err.println(CANNOT_START_CLIENT.toString());
}
}
}
As you can see I am connecting to the Headset and Handsfree service ports of my phone and I am allowing my program to prompt the user for AT Commands so that I can dial out/receive calls by entering AT Commands. I am able to send these AT Commands, but the problem is I cannot make my PC a headset of my phone. For example, if I dial a call out (by entering ATDnnnnnnnnnn), I still need to use my phone to talk -- I want to use my PC mic and speakers to talk instead. What did I leave out in my code?
Thank you very much in advance.