Welcome, Guest. Please login or register.

Login with username, password and session length
May 09, 2008, 05:08:47 PM
Pages: [1]
  Print  
Topic: Java Bluetooth Programming: Using the PC as a headset for my mobile phone  (Read 172 times)
« on: March 25, 2008, 06:58:54 AM »
MOOMOOMILK
Newbie

View Profile
*
Karma: +0/-0
Posts: 1



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:

Code:
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.
Logged
 
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC