views:

488

answers:

1

Is there anything in the blackberry api or in j2me which would allow communications and/or pairing to a bluetooth device using the MAC address? (Assuming the device is not-discoverable)

+1  A: 

Do you want to know how to generally connect to a device given the MAC address or are you interested in how to circumvent Blackberry specific security/permission issues? I have no idea for the latter case, but for the first case, here is an approach:

To do a service search on a remote device, you need an instance of the class javax.bluetooth.RemoteDevice, which you usually retrieve by a device search using a DiscoveryAgent. If you already have a device address you cannot create a RemoteDevice instance directly because the corresponding constructor of RemoteDevice is protected.

To circumvent this, you can create a new class extending RemoteDevice. In this derived class declare a public constructor which takes the device address. This public constructor is then able to call the protected super constructor:

public class MyRemoteDevice extends RemoteDevice {
    public MyRemoteDevice(String addr) {
        super(addr);
    }
}

Now you have RemoteDevice for a specific device address without doing a device scan and without querying the known devices list.

Note: While this approach works according to my experience, it may still fail on a Blackberry device in case RIM implemented some hidden functionality in the RemoteDevice class which is ignored if a RemoteDevice instance gets created as shown here.

Oben Sonne
This will give me a device, but how would I go about getting the actual "Connection" back. (Where i can do send/receive actions)I actually found I can use Connector.open("btspp://MAC_ADDRESS:Channel_ID");So that actually worked for me. Is that the best way to do it though?
OTisler
If you now the Channel_ID, then it's just perfect to create a connection that way. Creating a device as described above is useful if you now the device address but not the channel (because it is assigned dynamically and published by the service discovery protocol - SDP). In that case you can use the device to do a service search to finally get the channel that is used for a specific SPP service. However, with constant channel IDs your approach is just fine.
Oben Sonne