Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.0.5 for Windows
  Go To Table Of Contents
Go To Index


17 JSR 82: Bluetooth and OBEX Support

The 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:

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

17.1 Setting OBEX and Bluetooth Properties

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

  1. In the device selector right-click on a CLDC device.

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

  2. 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't 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.

17.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.

  1. Use DefaultCldcPhone1 to launch Bluetooth Demo, then launch Bluetooth Demo on DefaultCldcPhone2.

  2. The demo gives you a choice of Server or Client.

  3. On the first emulator, highlight Server and use the left 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 left soft button). The icon color changes from purple to green, indicating it is published.

  4. 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.

17.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.

  1. 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 DefaultCldcPhone1. Repeat and choose DefaultCldcPhone2.

  2. In the first emulator, launch the application then 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".

  3. 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.

  4. 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.