hello, the following code set the local device as discoverable (GIAC), and if you want, you can serch for nearby devices in discoverable mode, and then it makes a list with discovered devices.

i tested the following code in the wireless toolkit and it works good, but i ran the midlet in two nokia 6280 (real devices) so both are in discoverable mode and in one of them i hit Search, but nothing is detected, all bluetooth capabilities are activated and i granted all requested permissions

have you some idea where is the mistake?
thanks in advance, soraya

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.bluetooth.*;
import java.lang.*;
import java.io.*;

public class BuscadorDispositivos extends MIDlet implements CommandListener, DiscoveryListener{
public Display display;
public List list;
public Command buscar, salir, cancelar;
public LocalDevice localDevice;
public DiscoveryAgent da;
public boolean inq = false;

public void startApp() {
display = Display.getDisplay(this);
buscar = new Command("Buscar", Command.ITEM, 1);
salir = new Command("Salir", Command.EXIT, 1);
cancelar = new Command("Cancelar", Command.CANCEL, 1);
list = new List("Buscador de Dispositivos", List.IMPLICIT);
list.addCommand(buscar);
list.addCommand(salir);
list.setCommandListener(this);
display.setCurrent(list);
try {
localDevice = LocalDevice.getLocalDevice();
localDevice.setDiscoverable(DiscoveryAgent.GIAC);
}
catch (BluetoothStateException e){
list.append("\"Fallo en la configuración del dispositivo Bluetooth\"", null);
notifyDestroyed();
destroyApp(false);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable d) {
if (command == buscar) {
list.removeCommand(buscar);
list.addCommand(cancelar);
buscarDispositivos();
}
else if (command == salir) {
if (inq) da.cancelInquiry(this);
try {
localDevice.setDiscoverable(DiscoveryAgent.NOT_DISCOVERABLE);
}
catch (BluetoothStateException e){}
notifyDestroyed();
destroyApp(false);
}
else if(command == cancelar) {
if (inq) da.cancelInquiry(this);
}
}
public void buscarDispositivos() {
try {
list.deleteAll();
list.append("\"Buscando Dispositivos...\"", null);
inq = true;
da = localDevice.getDiscoveryAgent();
da.startInquiry(DiscoveryAgent.GIAC, this);
}
catch (BluetoothStateException e){
list.append("\"Fallo en la búsqueda de Dispositivos\"", null);
notifyDestroyed();
destroyApp(false);
}
}
public void deviceDiscovered(RemoteDevice remote, DeviceClass cod) {
try {
String friendly = remote.getFriendlyName(true);
String address = remote.getBluetoothAddress();
list.append(" - " + friendly + " : " + address, null);
}
catch(IOException e) {};
}
public void inquiryCompleted(int discType) {
switch (discType) {
case DiscoveryListener.INQUIRY_TERMINATED:
list.append("\"Búsqueda Cancelada\"", null);
break;
case DiscoveryListener.INQUIRY_COMPLETED:
list.append("\"Búsqueda finalizada\"", null);
break;
}
inq = false;
list.removeCommand(cancelar);
list.addCommand(buscar);
}
public void servicesDiscovered(int transId, ServiceRecord[] records) {}
public void serviceSearchCompleted(int transId, int respCode) {}
}