Question Locked

Access USB Bluetooth device using Java

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

}

3 replies

by yorahman

you use the microedition libs in your application. this is not going to work as the the networking in J2me relies completly on the GCF which dosnt exist in Java SE. you have to use a jsr - 82 implementation for standerd edition which mostly not free.

This discussion is closed to new replies.