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
New Contributor
Posts: 4
Registered: ‎03-13-2012
My Device: Blackberry developer

bluetooth connection problem

I have problem with the bluetooth connection from the blackberry , am a developer and need anybody to help me in it , i try to access a bluetooth printer "Blue Bamboo p25 " from my app to print some data ,it's my code  /*

 

BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();

s=info[0].toString();

Dialog.inform("Done1");

 

if( info == null || info.length == 0 ) // No devices paired

{

Dialog.alert("No bluetooth serial ports available for connection.");

}

else{

Dialog.inform( info[0].toString());

}

StreamConnection _bluetoothConnection = (StreamConnection)Connector.open(s, Connector.READ_WRITE);

Dialog.inform("Done2");

DataOutputStream _dout = _bluetoothConnection.openDataOutputStream();

String s="test print test print";

Dialog.inform("Done3");

_dout.write(s.getBytes());

Dialog.inform("Done4");

 

if (_bluetoothConnection != null) {

 

try{

_bluetoothConnection.close();

}

catch(IOException ioe) {

}

}

if (_dout != null) {

 

try{

_dout.flush();

_dout.close();

}

catch(IOException ioe) {

}

}

 

_bluetoothConnection =

null;

 

_dout =

null;

*/

and when run the app only "Done1" & "info[0].tostring()" are displayed, it means that the problem done at this line /*StreamConnection _bluetoothConnection = (StreamConnection)Connector.open(s, Connector.READ_WRITE);*/

can anybody tell me what's the wrong with this code ? and tell me what should i do to make the perfect bluetooth connection ? ..

New Contributor
Posts: 4
Registered: ‎03-13-2012
My Device: Blackberry developer

Re: bluetooth connection problem

please anybody help me ..

New Contributor
Posts: 4
Registered: ‎03-13-2012
My Device: Blackberry developer

Re: bluetooth connection problem

is my question is difficult to such a degree ? :mansad:

New Developer
Posts: 4
Registered: ‎02-23-2012
My Device: Curve 8520

Re: bluetooth connection problem

Is your code running in a background Thread? If it is not, it will not work because Connector.open blocks the Main Event Thread. Change it to a background Thread and it should work