Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300
Accepted Solution

Detecting Bluetooth Devices

Hi

I want to know how to detect active bluetooth devices programmatically. I am using JDE 4.3.0. 

Please help.

 

Thanks.

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Detecting Bluetooth Devices

Give a look at "javax.bluetooth" package.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300

Re: Detecting Bluetooth Devices

I tried testing javax.bluetooth APIs

 

Here is my simple testing code.

 

try { LocalDevice localDevice = LocalDevice.getLocalDevice(); DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent(); MyDiscoveryListener myDiscoveryListener = new MyDiscoveryListener(); //DiscoveryAgent.startInquiry(DiscoveryAgent.CACHED, myDiscoveryListener); discoveryAgent.startInquiry(DiscoveryAgent.CACHED, myDiscoveryListener); } catch(Exception e) { //e.printStackTrace(); Dialog.alert("bluetooth exception: "+e.getMessage()); }

 

 Here is the implementation of MyDiscoveryListener class -

class MyDiscoveryListener implements DiscoveryListener { MyDiscoveryListener() { } public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { try { Dialog.alert("Device discovered " + btDevice.getFriendlyName(true)); } catch(Exception e) { } } public void inquiryCompleted(int discType) { Dialog.alert("Inquiry Completed"); } public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { Dialog.alert("Services Discovered"); } public void serviceSearchCompleted(int transID, int respCode) { Dialog.alert("Service Search completed"); } }

 

 

But it is getting exception and alerts with dialog- "bluetooth exception: null"

 

I have no idea why my application is getting this exception. Can you help?

 

 

Please use plain text.
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300

Re: Detecting Bluetooth Devices

I have modified the code and tried in device

Here is the modified code..

 

 

try { LocalDevice localDevice = LocalDevice.getLocalDevice(); DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent(); MyDiscoveryListener myDiscoveryListener = new MyDiscoveryListener(); discoveryAgent.startInquiry(DiscoveryAgent.CACHED, myDiscoveryListener); } catch(BluetoothStateException bse) { Dialog.alert("BluetoothStateException exception: "+bse.toString()); }

 

 And It shows dialog: Uncaught exception: java.lang.IllegalArgumentException.

Do you have any idea?

 

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Detecting Bluetooth Devices

Can you check with the example which is shipped with Sun tool kit for javax.bluetooth implementation.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300

Re: Detecting Bluetooth Devices

I have checked. They did almost same thing.

 

Please use plain text.
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300

Re: Detecting Bluetooth Devices

It worked after changing

DiscoveryAgent.CACHED

 

to

DiscoveryAgent.GIAC

 

I don't know what is the reason.

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Detecting Bluetooth Devices

CACHED:

Used with the retrieveDevices() method to return those devices that were found via a previous inquiry.

 

GIAC:

The inquiry access code for General/Unlimited Inquiry Access Code (GIAC).

 


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
arif
Posts: 57
Registered: ‎04-07-2009
My Device: 8300

Re: Detecting Bluetooth Devices

Thanks.
Please use plain text.
New Developer
foxkis
Posts: 9
Registered: ‎01-25-2010
My Device: 8300
My Carrier: Telus

Re: Detecting Bluetooth Devices

This other post talks about the getLocalDevice() call returning null (see http://supportforums.blackberry.com/t5/Java-Development/Bluetooth-LocalDevice-getLocalDevice-NullPoi...)

 

Your code obviously doesn't suffer the same trouble. Do you do something different/magic in the setup before making the LocalDevice.getLocalDevice() call? I am currently struggling with the "null" issue which you appear to have solved.

 

All responses/hints gratefully received!

Please use plain text.