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 Developer
Posts: 28
Registered: ‎06-18-2012
My Device: Developer

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());
}

Developer
Posts: 16,578
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
New Developer
Posts: 28
Registered: ‎06-18-2012
My Device: Developer

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

@simon_hain: Thanks for the quick reply. Let me try it.
New Developer
Posts: 28
Registered: ‎06-18-2012
My Device: Developer

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.
Developer
Posts: 16,578
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
New Developer
Posts: 28
Registered: ‎06-18-2012
My Device: Developer

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?
Developer
Posts: 16,578
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
New Developer
Posts: 28
Registered: ‎06-18-2012
My Device: Developer

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.