Help Center
Local Navigation
- Managing applications
- Storing data
-
Creating connections
- Network connections and transport types
- Connections
-
Wi-Fi connections
- Wireless access families
- Retrieve the wireless access families that a BlackBerry device supports
- Determine if a BlackBerry device supports multiple wireless access families
- Determine the wireless access family transceivers that are turned on
- Turn on the transceiver for a wireless access family
- Turn off the transceiver for a wireless access family
- Check if the Wi-Fi transceiver is turned on
- Check if the Wi-Fi transceiver is connected to a wireless access point
- Retrieve the status of the wireless access point or the active Wi-Fi profile
- Retrieve the wireless network name
- Open a Wi-Fi socket connection
- Open a Wi-Fi HTTP connection
- Open a Wi-Fi HTTPS connection
- Enhanced Network API
- Controlling access to APIs and application data
- Testing a BlackBerry device application
- Packaging and distributing a BlackBerry Java Application
- Localizing BlackBerry device applications
- Custom user authentication
- Glossary
- Provide feedback
- Related resources
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Documentation for Developers
>
Java Development Guides and API Reference
>
Core - Development Guide - BlackBerry Java Application - 5.0
Use a Bluetooth serial port connection
You can use the Bluetooth® API (net.rim.device.api.bluetooth) to let your BlackBerry® device application access the Bluetooth Serial Port Profile and initiate a server or client Bluetooth serial port connection to a computer or other Bluetooth enabled device.
- Import the following classes:
- Import the javax.microedition.io.StreamConnection interface.
- Invoke Connector.open(), providing the serial port information that BluetoothSerialPort.getSerialPortInfo() returns as a parameter to open a Bluetooth
connection.
BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo(); StreamConnection _bluetoothConnection = (StreamConnection)Connector.open( info[0].toString(), Connector.READ_WRITE );
- To send data on the Bluetooth connection, invoke openDataOutputStream() or openOutputStream().
DataOutputStream _dout = _bluetoothConnection.openDataOutputStream();
- Use the write methods on the output stream to write data.
private static final int JUST_OPEN = 4; _dout.writeInt(JUST_OPEN);
- To receive data on the Bluetooth connection,
in a non-main event thread, invoke openInputStream() or openDataInputStream(). Use the read methods on the input stream to read the data.
DataInputStream _din = _bluetoothConnection.openDataInputStream(); String contents = _din.readUTF();
- Invoke close()on the input and output streams, and on the Bluetooth serial port connection object to close the Bluetooth connection. The close() method can throw IOExceptions. Make sure the BlackBerry
device application implements exception handling.
if (_bluetoothConnection != null) { try { _bluetoothConnection.close(); } catch(IOException ioe) { } } if (_din != null) { try { _din.close(); } catch(IOException ioe) { } } if (_dout != null) { try { _dout.close(); } catch(IOException ioe) { } } _bluetoothConnection = null; _din = null; _dout = null;
Next topic:
Wi-Fi connections
Previous topic: Use a USB or serial port connection