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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
MudassirAli
Posts: 28
Registered: ‎06-18-2012
My Carrier: NA

Connecting a BlackBerry Bold 9900 with a Bluetooth SPP device

[ Edited ]

Hello Community,

 

I am trying to connect BlackBerry Bold 9900 to a Bluetooth device having SPP. But when I try to open a connection, it fails with an exception (java.io.IOException: Unable to connect.) I cannot understand why its not getting connected.

I am using the BlackBerry JDE Eclipse plugin with platform version 4.5.

Posting the code here, please someone have a look at it;

 

public final class ReaderScreen extends MainScreen {

private BluetoothSerialPortInfo[] serialPortInfo;
private StreamConnection bluetoothConnection;

private DataInputStream inputStream;
private String contents;

private LabelField label;

 

/**
 * Creates a new ReaderScreen object
 */
public ReaderScreen() {

setTitle("Reader");

label = new LabelField("Started");

add(label);

 

serialPortInfo = BluetoothSerialPort.getSerialPortInfo();

if (serialPortInfo == null) {
appendLabel("info is null.");
} else {
appendLabel("info is not null.");
}

 

appendLabel("Going to open connection...");

appendLabel("Connecting to device " + serialPortInfo[0].toString());

 

try {
appendLabel("Inside the first thread.");

bluetoothConnection = (StreamConnection) Connector.open(
serialPortInfo[0].toString(), Connector.READ);

 

if (bluetoothConnection == null) {
appendLabel("connection is null.");
} else {
appendLabel("connection is not null.");
}
} catch (IOException e) {
e.printStackTrace();

appendLabel("Exception in constructor");
appendLabel(e.toString());
} catch (Exception e) {
e.printStackTrace();

appendLabel("Gen Exception in constructor");
appendLabel(e.toString());
}

 

appendLabel("Starting thread...");
UiApplication.getUiApplication().invokeLater(new ReaderThread());
}

Please use plain text.
Developer
simon_hain
Posts: 13,754
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

you start a thread using start(), not invokelater.
blocking operations, like I/O, should be done on a separate thread.

take a look at the bluetooth demo in your samples folder.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
MudassirAli
Posts: 28
Registered: ‎06-18-2012
My Carrier: NA

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

@simon_hain: Thanks for the quick reply. Let me try it.
Please use plain text.
New Developer
MudassirAli
Posts: 28
Registered: ‎06-18-2012
My Carrier: NA

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

Simon, there is no method as start() available in my thread. I am implementing the Runnable interface and its (thread class's) object is also showing a run() method.
Please use plain text.
Developer
simon_hain
Posts: 13,754
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

you can also create a thread with a runnable.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
MudassirAli
Posts: 28
Registered: ‎06-18-2012
My Carrier: NA

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

Yeah. But I can't figure out why it can't connect. Can you suggest me any workaround or anything I am forgetting in my approach?
Please use plain text.
Developer
simon_hain
Posts: 13,754
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

did you run the sample app? can it connect?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
MudassirAli
Posts: 28
Registered: ‎06-18-2012
My Carrier: NA

Re: Connecting a BlackBerry Bold 9900 with a Bluetooth SPP deviceca

Yeah. I ran it several times. As I said before, it is throwing the IOException.
Please use plain text.