Access USB Bluetooth device using Java - TechRepublic
Question
August 25, 2007 at 12:10 PM
ocsam2002

Access USB Bluetooth device using Java

by ocsam2002 . Updated 15 years, 10 months ago

Please does anyone know how I can gain access to my USB bluetooth device using JSR-82 API. With my bluetooth device turned on, when i run my code belox: I get a BluetoothStateException

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class PcServer {

/**
* @declarations
*/
protected LocalDevice lDevice;

public PcServer()throws BluetoothStateException {
try{
// retrieve the local Bluetooth device object
lDevice = LocalDevice.getLocalDevice();
}catch(Exception e){
e.printStackTrace();
}

// retrieve the Bluetooth address of the local device
String address = lDevice.getBluetoothAddress();
log(“My Bluetooth address is ” + address);
// retrieve the name of the local Bluetooth device
String name = lDevice.getFriendlyName();
log(“My friendly name is ” + name);

}

/**
* @param args
*/
public static void main(String[] args) throws BluetoothStateException {
// TODO Auto-generated method stub
PcServer pcSvr = new PcServer();
log(“Server String…”);log(” “);
log(pcSvr);
}

}

This discussion is locked

All Comments