views:

281

answers:

3

i search all over the web and i cannot find anwser for my simple question: how to display in j2me list of all bluetooth devices in neighbourhood?

A: 

First, you need to choose a bluetooth stack.

You have a choice of BlueCove or Avetana (these too I'm aware of).

Then search their documentation for "device discovery".

Bozho
You can only use JSR82 in Java ME
funkybro
@funkybro - uh.. both libraries I gave are implementations of JSR-82.. so what's the problem?
Bozho
A: 

You can only use handsets that have JSR82 to do this.

This site gives a full example.

funkybro
+1  A: 

First, bear in mind that in the emulator you can't detect 'real' Bluetooth devices without a third-party JSR-82 library such as Bluecove (it's a desktop implementation for Java Bluetooth). But when you deploy to a JSR-82 capable phone, it should work.

But otherwise, it's easy with JSR-82! You can use the DiscoveryAgent class.

LocalDevice local = LocalDevice.getLocalDevice();  
DiscoveryAgent agent = local.getDiscoveryAgent();
boolean complete = agent.startInquiry(DiscoveryAgent.GIAC, new DiscoveryListener() {
   public void deviceDiscovered(RemoteDevice device, DeviceClass cod) {
      System.out.println("Discovered: " + device.getFriendlyName());    } 
});
while(!complete) {
    // wait until discovery completes before continuing 
}

Instead of printing the discovered devices as above, you could always put them into the Hashtable or Vector. The deviceDiscovered() method gets called everytime a device is discovered whilst the inquiry is running, and the inquiry usually returns in a decent time (a matter of 10s of seconds).

David Johnson