0 Replies Latest reply on Nov 1, 2010 1:16 AM by 807645

    Bluetooth inquiry makes phone hanging


      I got interested into bluetooth, after seeing some great applications, and started programming in J2ME.

      The following code searches for devices in the BCC (Bluetooth Control Center) with the retrieveDevices() method and returns the bluetoothaddres of the first device found in the RemoteDevice[] array, that is if any PREKNOWN or CACHED devices our found. After succesfully transfering and running the application on my cellphone the lines in the form show:
      -"no CACHED devices found"
      -"no PREKNOWN devices found"
      Which looks strange to me because I have a few pre-paired devices on my cellphone.

      So I added the startInquiry() method, compiled the applet and ran it on my cellphone (Nokia 6303i).

      Now when I run the applet there is a progress bar appearing on my screen, which appeared before also when I only used the retrieveDevices() method, and that's it. I guess this is because the device is searching for nearby BT devices but even after 30 minutes this progress bar is still on my screen.

      I was hoping that any of you guys could see the mistake in my code, I know I don't. Any ideas?
      Thanks in advance,

      import javax.microedition.lcdui.*;
      import javax.microedition.midlet.*;
      import javax.bluetooth.*;
      import java.util.*;
      public class Eigenschappen extends MIDlet implements CommandListener,DiscoveryListener{
           private Form form;
           private LocalDevice local;
           private DiscoveryAgent agent;
           private Display display;
           private Vector deviceList;
           private boolean booleaninquiry;
           public void startApp(){
           deviceList = new Vector();
                local = LocalDevice.getLocalDevice();
                }catch(BluetoothStateException bse){}
           agent = local.getDiscoveryAgent();
           String eig = LocalDevice.getProperty("bluetooth.l2cap.receiveMTU.max");
           RemoteDevice[] remotecache = agent.retrieveDevices(DiscoveryAgent.CACHED);
           RemoteDevice[] remotepreknown = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
           form = new Form("Properties");
           form.append("The MTU max is " + eig);
           if(remotecache != null){
           form.append("CACHED = " + remotecache[1].getBluetoothAddress());
           }else{form.append("no CACHED devices found");}
           if(remotepreknown != null){
           form.append("PREKNOWN = " + remotepreknown[1].getBluetoothAddress());
           }else{form.append("no PREKNOWN devices found");}
           if(remotecache == null && remotepreknown == null){
                booleaninquiry = agent.startInquiry(DiscoveryAgent.GIAC,this);
                     }catch(Exception e){}
                }catch(BluetoothStateException bse){}
                form.append("Inquiry gestart");
                }else{form.append("Inquiry niet gestart");}
           int sizeListInt = deviceList.size();
           String sizeListString = String.valueOf(sizeListInt);
           form.append("Number of found devices " + sizeListString);
           display = Display.getDisplay(this);
           public void pauseApp(){
           public void destroyApp(boolean unconditional){
           public void commandAction(Command c,Displayable d){
           public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod){
           public void servicesDiscovered(int transID, ServiceRecord[] servRecord){
           public void inquiryCompleted(int discType){
           public void serviceSearchCompleted(int transID, int respCode){