18 JSR 82: Bluetooth and OBEX Support

This chapter describes how the Oracle Java ME SDK implements the Bluetooth and OBEX APIs.

The Oracle Java ME SDK 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:

The Bluetooth API provides an interface to Bluetooth wireless networking, including device discovery and data exchange.

The Oracle Java ME SDK emulator enables you to develop and test applications that use Bluetooth without having actual Bluetooth hardware. The SDK simulates a Bluetooth environment for running emulators. Multiple emulator instances can discover each other and exchange data using the Bluetooth API.

18.1 Setting OBEX and Bluetooth Properties

The Oracle Java ME SDK enables you to configure the Bluetooth and OBEX simulation environment. Because the simulation requires a sender and receiver, Bluetooth settings are configured separately for each device. Follow these steps to set device properties.

In the device selector right-click on a CLDC device and select Properties.

The device properties are displayed in the Properties window. If you do not see this window, select Window > Properties from the NetBeans toolbar.

Scroll down to see the Bluetooth and OBEX properties. When you click a property a description is shown in the description area. If you can not see this area, right click a property and select Show Description Area.

The System Properties 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.

bluetooth.sd.trans.max

The maximum number of concurrent service discovery transactions. The default is 8.

bluetooth.sd.attr.retrievable.max

The maximum number of service attributes to be retrieved per service record.The default is 16.

bluetooth.master.switch

Enable/disable a master/slave switch. Enabled by default.

bluetooth.l2cap.receiveMTU.max

The maximum ReceiveMTU size in bytes supported in L2CAP. This is the maximum payload size this connection can accept.

The default value is 672.

OBEX Maximum Packet Length

The default is 4096 bytes.

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.

Device is discoverable

Enabled by default.

Authentication is enabled

Enabled by default.

Encryption is enabled

Enabled by default.

Authorization is enabled

Enabled by default.

18.2 Running the Bluetooth Demo

This application contains MIDlets that demonstrate the use of JSR 82's Bluetooth API. It shows how images can be transferred between devices using Bluetooth.

You must run two emulator instances to see this process, and each device must have a different phone number.

Use JavaMEPhone1 to launch Bluetooth Demo, then launch Bluetooth Demo on JavaMEPhone2.

The demo gives you a choice of Server or Client.

On the first emulator, highlight Server and use the right softbutton to choose OK.

The server starts and displays a list of images. At the beginning, none of the images are available on the Bluetooth network.

Select the image you want to make available.

Press Publish image (the right soft button). The icon color changes from purple to green, indicating it is published.

On the second emulator running the Bluetooth Demo, highlight Client and choose OK. The MIDlet displays "Ready for images search". Click the Find soft button. The MIDlet finds the other emulator and gets a list of published images. Select one from the list and choose Load.

If you are running the demonstration in a trusted protection domain, the image is transferred using simulated Bluetooth and is shown on the client emulator.

If you are not running in a trusted protection domain, the first emulator (the server) displays a prompt asking if you want to authorize the connection from the client. Choose Yes. The image is displayed in the client emulator.

18.3 Running the OBEX Demo

This application shows how to transfer image files between emulator instances using the OBEX API. This demonstration shows the use of OBEX over a simulated infrared connection.

Launch two instances of the emulator. One listens for incoming connections, while the other attempts to send an image.

For example, right-click ObexDemo, select Run With... and choose the device JavaMEPhone1. Repeat and choose JavaMEPhone2.

In the first emulator, choose Receive Image. (Depending on your security level, the application warns that an OBEX connection allows other devices to talk to yours and asks, "Is it OK to make the connection?" Choose Yes.) Choose Start to run the application. The listener emulator displays a screen reading "Waiting for connection".

In the second emulator (the sender), choose Send Image and press the Start soft key. Select an image from the list and choose Send. (Depending on your security level, the application warns that the demo wants to make an outgoing client connection, and asks if it is OK. Choose Yes.) The Send Image utility uploads the image.

In the listening emulator, the utility displays information about the incoming image and asks "Would you like to receive it?" Choose yes.

The image you selected is transferred over the simulated infrared link and displayed on the first emulator.

A script enabled browser is required for this page to function properly.A script enabled browser is required for this page to function properly.A script enabled browser is required for this page to function properly.A script enabled browser is required for this page to function properly.