Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
lili
Posts: 5
Registered: 07-29-2008
Accepted Solution

Detect when Bluetooth is disconnected

Hello,

 

I have a device that I am trying to communicate with from my BlackBerry using Bluetooth.

 

I am able to connect to it using the method Connector.open(info, Connector.READ_WRITE );

I can also read and write using the input and output streams. 

 

However I need to be able to detect when the port is disconnected from the remote device. I was thinking of using BluetoothSerialPortListener. To use this I try to connect to the device using this method:

 

 

listener = new MyBluetoothListener(); _serialPort = new BluetoothSerialPort(info[i].toString(), BluetoothSerialPort.BAUD_9600, BluetoothSerialPort.DATA_FORMAT_DATA_BITS_8 | BluetoothSerialPort.DATA_FORMAT_PARITY_NONE | BluetoothSerialPort.DATA_FORMAT_STOP_BITS_1, BluetoothSerialPort.FLOW_CONTROL_NONE, 2048, 2048, listener);

 

 

This does not appear to be working. The above call works fine and I don't get any exceptions. However, I also don't get the deviceConnected() callback in my listener.

In the console output I see the following and nothing else after this:

BT: allocSerialPort 81159234
BT: sdpAddRecord
BT: allocSdpAttributeData

 

Is there something I'm missing here?  

 

To summarize, I have two questions:

1. Why isn't the connection using BluetoothSerialPort working?

2. Assuming I can't get that to work is there a way I can detect a disconnect when using the Connector.open() method? 

 

Thanks in advance for your help.

 

Please use plain text.
Developer
peter_strange
Posts: 14,611
Registered: 07-14-2008

Re: Detect when Bluetooth is disconnected

I am connecting to a Bluetooth device using very similar code to yours, with two exceptions:

 

1) You use info[i].toString(), as the first parameter, I just use the equivalent of info[i]

2) I'm using BluetoothSerialPort.BAUD_115200,

 

The listener receives disconnections as I would expect.

 

The messages I see when debugging this re as follows:

BT: allocSerialPort 814ee52c
BT: BTEVENT_LINK_CONNECT_CNF
net.rim.bluetooth: DC00
BT: BTEVENT_LINK_POLICY_CHNG received
net.rim.bluetooth: EC00

 

This test was run on an 8900 running 4.6.1.199.

 

Hope this helps.

Please use plain text.
New Developer
lili
Posts: 5
Registered: 07-29-2008

Re: Detect when Bluetooth is disconnected

Thank you for the response. That fixed my problem.

 

I removed the .toString() and used just info[i] and everything works fine now.

I can connect and my listener is getting the callbacks.  

 

Thanks.  

 

Please use plain text.
New Developer
ruso
Posts: 8
Registered: 07-10-2008

Re: Detect when Bluetooth is disconnected

HI,
 
I Need help on Blackberry Bluetooth Connectivity for sending/receiving audio Data to/from connected devices. If you have any information regarding that , Please guide me.
I want to share my already playing music to other bluetooth enable device using coding.
I tried for RIM API BluetoothSerialPort  and BluetoothSerialPortInfo but could not get success.
 
 
Thanks & Regards
Abhijeet R Namdeo
Please use plain text.
Developer
peter_strange
Posts: 14,611
Registered: 07-14-2008

Re: Detect when Bluetooth is disconnected

[ Edited ]
Please use plain text.