Contents Previous Next Index

Chapter   11

Using the Bluetooth and OBEX APIs


The J2ME Wireless Toolkit emulator supports JSR 82, the Java APIs for Bluetooth. JSR 82 includes two independent APIs:

This chapter describes how the J2ME Wireless Toolkit implements the Bluetooth and OBEX APIs.

11.1 Bluetooth Simulation Environment

The J2ME Wireless Toolkit emulator allows 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, “Application Demonstrations.”

11.2 OBEX Over Infrared

The J2ME Wireless Toolkit 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 J2ME Wireless Toolkit allows you to configure the Bluetooth and OBEX simulation environment. Choose Edit > Preferences... from the KToolbar menu to see the following window.

FIGURE 38  –  Bluetooth and OBEX preferences

Bluetooth and OBEX preferences

11.3.1 OBEX Preferences

Devices using IrDA in the real world discover other devices by “listening”. You can configure how long the J2ME Wireless Toolkit 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...") will block 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 will result in more packets and more packet overhead.

11.3.2 Bluetooth Discovery Timeout

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

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 may provide a GUI to customize Bluetooth settings. In the J2ME Wireless Toolkit, the BCC is configured using the BCC Properties tab of the Bluetooth preferences. The properties are as follows:

TABLE 7  –  BCC properties
Property
Description
Enable Bluetooth support
If this property is disabled, then 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 may have the Bluetooth feature turned off.
Device is discoverable
This property indicates whether or not this emulator can be discovered by other emulators.
Friendly name
The friendly name is a human-readable name for the emulator in the simulated Bluetooth environment. If the name is left blank, the emulator will not support the “friendly name” feature.
Encryption
This property determines whether connection encryption is supported (on) or not (off). In addition, the force settings means all connected must be encrypted. See the documentation for RemoteDevice’s encrypt() method for details.
Authorization
This is similar to the Encryption property. See RemoteDevice’s authorize() method.
Authentication
This is similar to Encryption and Authorization. See RemoteDevice’s authenticate() method.

 


Contents Previous Next Index J2ME Wireless Toolkit User's Guide
J2ME Wireless Toolkit 2.2