×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    10

    Can't discover any bluetooth devices with DiscoveryAgent

    I am trying to get a list of bluetooth devices on an N97 (S60 5th edition) phone using the Java API. I have tried DiscoveryAgent.retrieveDevices and DiscoveryAgent.startInquiry, but neither approach ever finds any devices. I have tried both methods with devices that are paired and currently connected to the phone, devices that are paired but not present, and devices that the built-in settings tool has discovered, but are not paired. It's not throwing any exceptions. Calls to retrieveDevices(DiscoveryAgent.PREKNOWN) always return null, and when I use startInquiry, I get the inquiryCompleted callback with INQUIRY_COMPLETED, but the deviceDiscovered callback never happens. I know the phone's bluetooth is working because it detects and pairs with the devices in the bluetooth settings tool, and connects and disconnects appropriately when the devices are nearby. I don't have a valid certificate for signing the app, so it is currently unsigned, but I haven't seen anything indicating that this functionality isn't available to unsigned apps, and the phone is configured to ask for permissions if needed, which it does not.



    javax.bluetooth.DiscoveryAgent da = javax.bluetooth.LocalDevice.getLocalDevice().getDiscoveryAgent();
    if (da == null) return new String[] { "Discovery agent unavailable" };
    javax.bluetooth.RemoteDevice[] devices = da.retrieveDevices(javax.bluetooth.DiscoveryAgent.PREKNOWN);
    //at this point, devices is always null

    javax.bluetooth.LocalDevice ldev = javax.bluetooth.LocalDevice.getLocalDevice();
    javax.bluetooth.DiscoveryAgent agent = ldev.getDiscoveryAgent();
    agent.startInquiry(javax.bluetooth.DiscoveryAgent.GIAC, new javax.bluetooth.DiscoveryListener() {
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    //this never gets called with any of the 3 scenarios above
    }
    public void inquiryCompleted(int discType) {
    //this always gets called after about 10 sec. with discType==DiscoveryListener.INQUIRY_COMPLETED
    }
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    //doesn't get called because we're not searching for services
    }
    public void serviceSearchCompleted(int transID, int respCode) {
    //doesn't get called because we're not searching for services
    }
    });



    Thanks!

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Can't discover any bluetooth devices with DiscoveryAgent

    since that is java scpecific question, maybe you could ask it in the Java section.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Does this help? All you can do is to inquiry for those devices in vicinity and Bluetooth visible. One of the various limitations of the Bluetooth API specification itself.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    10

    Re: Can't discover any bluetooth devices with DiscoveryAgent

    The inquiry isn't returning any devices, even when they are nearby, bluetooth visible, and detectable by the bluetooth settings. The only bluetooth device settings I have been able to find are under Settings -> Connectivity -> Bluetooth under the Paired devices tab. Is this the Bluetooth Control Center that post mentions, or is it located elsewhere on the phone? I have seen a couple posts in addition to that one saying that retrieveDevices(DiscoveryAgent.PREKNOWN) requires devices to be specified in the Bluetooth Control Center, but have not been able to locate anything with that name on the N97 device I am using for development.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    In Nokia world, PREKNOWN does not return anything. If a device was found, it might/will be listed in CACHED. To make it short, those two values are useless. Nevertheless, I do not know why deviceDiscovered is not called in your case. All I can recommend is to call startInquiry from a new thread just for that.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    10

    Re: Can't discover any bluetooth devices with DiscoveryAgent

    Calling startInquiry() in a new thread has no effect. I had also tried running the whole detection method in a new thread when I originally wrote it to make sure it wasn't tying up UI resources, but that also had no effect.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    That anonymous inner class could be a problem. Instead, try it with a normal implements DiscoveryListener. Nevertheless, this is Just guessing, as I never tried such a language beast in J2ME code, yet.

  8. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    10

    Re: Can't discover any bluetooth devices with DiscoveryAgent

    Tried moving the anonymous inner class into a public static class that implements DiscoveryListener...no change in behavior.

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Why do you use a static class? Just use a normal object. By the way for starters, I recommend a book …

Similar Threads

  1. Replies: 3
    Last Post: 2009-07-09, 18:32
  2. Bluesoleil Software
    By kencooper in forum Bluetooth Technology
    Replies: 9
    Last Post: 2008-08-29, 19:46
  3. [Moved] bluetooth application for nokia bluetooth capable devices
    By cutescar2nis in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-08-05, 09:23
  4. Bluetooth scanning for devices
    By drvdijk in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2008-03-20, 10:57
  5. Bluetooth devices information
    By merchan in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-11-06, 12:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×