C H A P T E R  11

Using the Bluetooth and OBEX APIs

The Sun JavaTM Wireless Toolkit for CLDC emulator supports JSR 82, the Java APIs for Bluetooth. The emulator is fully compliant with version 1.1 of the specification, which describes integration with the push registry. JSR 82 includes two independent APIs:

This chapter describes how the Sun JavaTM Wireless Toolkit for CLDC implements the Bluetooth and OBEX APIs.

11.1 Bluetooth Simulation Environment

The Sun JavaTM Wireless Toolkit for CLDC emulator enables you to develop and test application that use Bluetooth without having actual Bluetooth hardware. The toolkit simulates a Bluetooth environment for running emulators. Multiple emulator instances can discover each other and exchange data using the Bluetooth API.

For an example, see the documentation of BluetoothDemo in Appendix A.

11.2 OBEX Over Infrared

The Sun JavaTM Wireless Toolkit for CLDC implements OBEX transfer over simulated Bluetooth and infrared connections. The simulated infrared connection follows the IrDA standard (see http://www.irda.org/). Simulated infrared transfers can take place between multiple running emulators.

11.3 Setting OBEX and Bluetooth Preferences

The Sun JavaTM Wireless Toolkit for CLDC enables you to configure the Bluetooth and OBEX simulation environment. Choose Edit > Preferences and select Bluetooth/OBEX to display the following window.

FIGURE 11-1 Bluetooth and OBEX Preferences

Bluetooth/OBEX preferences with Bluetooth Internal Properties tab selected

11.3.1 OBEX Preferences

Devices using IrDA in the real world discover other devices by listening. You can configure how long the Sun JavaTM Wireless Toolkit for CLDC emulator waits to discover another device using the Discovery timeout field in the IrDA OBEX section of the preferences window. Enter a value in milliseconds.

At the API level, the discovery timeout value determines how long a call to Connector.open("irdaobex://discover...") blocks before it returns or throws an exception.

The maximum packet length affects how much data is sent in each packet between emulators. Shorter packet values result in more packets and more packet overhead.

11.3.2 Bluetooth Internal Properties

In the Bluetooth section of the preferences window, the Device discovery timeout is the amount of time, in milliseconds, the emulator waits while attempting to locate other devices in the simulated Bluetooth environment.

Bluetooth Address of Next Emulator is the Bluetooth address to be assigned to the first emulator instance. Subsequent instances of the emulator receive an automatically generated address.

11.3.3 Bluetooth System Properties

The System Properties tab in the Bluetooth section of the preferences contains properties that can be retrieved in an application using the getProperty() method in javax.bluetooth.LocalDevice.

The Bluetooth properties are fully described in the JSR 82 specification.

11.3.4 Bluetooth BCC Properties

The Bluetooth Control Center (BCC) controls Bluetooth settings. Some devices might provide a GUI to customize Bluetooth settings. In the Sun JavaTM Wireless Toolkit for CLDC, the BCC is configured using the BCC Properties tab of the Bluetooth preferences. The properties are as follows.

TABLE 11-1 BCC Properties



Enable Bluetooth support

If this property is disabled, LocalDevice.getLocalDevice() throws a BluetoothStateException and no connections can be created. This is useful to test the behavior of your application on devices that support JSR 82 but might have the Bluetooth feature turned off.

Device is discoverable

Indicates whether or not this emulator can be discovered by other emulators.

Friendly name

A human-readable name for the emulator in the simulated Bluetooth environment. If the name is left blank, the emulator does not support the friendly name feature.


Determines whether connection encryption is supported (on) or not (off). In addition, the force settings means all connections must be encrypted. See the documentation for RemoteDevice's encrypt() method for details.


Similar to the Encryption property. See RemoteDevice's authorize() method.


Similar to Encryption and Authorization. See RemoteDevice's authenticate() method.