×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    problems connecting with preknown remote device in java and bluetooth

    hello all, i used windows operation to pair my usb bluetooth dongle with a bluetooth enabled mobile phone. i am now writing an application that discovers remote devices and prints them out, but i am trying to add a code that will print a simple line like "Hi" to my bluetooth device that was already paired with my dongle as it gets discovered during the process. i tried using the retrieveDevices()method but i can't seem to figure it out correctly. it keeps printing the same "Hi" to all the devices found. i don't know if am doing this correctly as am just a beginner. but here is the part of the code that am having trouble with:

    Code:
      public void deviceDiscovered(RemoteDevice btdevice, DeviceClass cod) {
            
            System.out.println(" Device Found = " + btdevice.getBluetoothAddress());
    
            try {
                System.out.println(" Device Name = " + btdevice.getFriendlyName(false));
            } catch (IOException ex) {
                Logger.getLogger(BTHomeServer.class.getName()).log(Level.SEVERE, null, ex);
            }
                    DeviceFound.addElement(InqCompleted);
    
            RemoteDevice[] agent2 = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
            if(agent2 != null){
                int s = agent2.length;
                for(int i = 0; i<s; i++){
                    DeviceFound.elementAt(i);
             System.out.print((i+1)+ ". Hi " + btdevice.getBluetoothAddress());
                }
            }
    
           
        }

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: problems connecting with preknown remote device in java and bluetooth

    public RemoteDevice[] retrieveDevices(int option)

    Returns an array of Bluetooth devices that have either been found by the local device during previous inquiry requests or been specified as a pre-known device depending on the argument. The list of previously found devices is maintained by the implementation of this API. (In other words, maintenance of the list of previously found devices is an implementation detail.) A device can be set as a pre-known device in the Bluetooth Control Center.
    Parameters:
    option - CACHED if previously found devices should be returned; PREKNOWN if pre-known devices should be returned (which are pre-known may be paired or not)
    Returns:
    an array containing the Bluetooth devices that were previously found if option is CACHED; an array of devices that are pre-known devices if option is PREKNOWN; null if no devices meet the criteria
    Throws:
    IllegalArgumentException - if option is not CACHED or PREKNOWN

    DiscoveryAgent.PREKNOWN != Paired

    thanks,
    ~Amitabh

  3. #3
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: problems connecting with preknown remote device in java and bluetooth

    I guess you will have to save the device bt-names yourself in a RMS or something, and afterwards while the devices are found in a subsequent search compare them with what's in your RMS...

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    Re: problems connecting with preknown remote device in java and bluetooth

    thanks im2amit, will try that method and see how it goes. Must be very silly, i read that but did not see the full method declaration.

    tiger79, its for my pc side so i don't think i can use RMS(i think!) since its not for my mobile phone. i will try your solution too but was wondering what i could do. maybe i should use JDBC or MySQL. what you think?

    thanks anyway guys.

  5. #5
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: problems connecting with preknown remote device in java and bluetooth

    sorry I assumed you were developing on a J2ME device because of the code you posted, which is an implementation (and usage) of the JSR-82 API...
    Well then on your desktop you could use a lot, form a SQL database to simple textfiles...

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    And as your are in j2SE world, you could even use JNI or other means to get the list of paired devices.

Similar Threads

  1. Java Bluetooth Data transfer problems
    By cosminr in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2009-05-20, 15:08
  2. Replies: 4
    Last Post: 2009-04-27, 19:51
  3. Connecting to a known bluetooth device
    By avis86 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-02-03, 14:10
  4. connecting to a bluetooth device automatically
    By kpmkhaja1 in forum Bluetooth Technology
    Replies: 3
    Last Post: 2006-11-01, 10:42

Posting Permissions

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