|Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.0.5 for Windows
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:
The 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.
For an example, see Section 17.2, "Running the Bluetooth Demo".
For an example, see Section 17.3, "Running the OBEX Demo".
This chapter describes how the Java ME SDK implements the Bluetooth and OBEX APIs.
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.
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.
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.
The maximum number of concurrent service discovery transactions.
The default is 8.
The maximum number of service attributes to be retrieved per service record.
Enable/disable a master/slave switch.
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.
IrDA OBEX Discovery Timeout
The default is 10000 milliseconds.
Devices using IrDA in the real world discover other devices by listening. At the API level, the discovery timeout value determines how long a call to
") blocks before it returns or throws an exception.
You must run two emulator instances to see this process, and each device must have a different phone number.
Use DefaultCldcPhone1 to launch Bluetooth Demo, then launch Bluetooth Demo on DefaultCldcPhone2.
The demo gives you a choice of Server or Client.
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.
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.
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 DefaultCldcPhone1. Repeat and choose DefaultCldcPhone2.
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".
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.