Oracle® Java Micro Edition Software Development Kit Developer's Guide Release 3.2 for Eclipse on Windows E37550-02 |
|
Previous |
Next |
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.
For an example, see Section 15.2, "Running the Bluetooth Demo."
The OBEX API allows applications to use the Object Exchange (OBEX) protocol over Bluetooth or other communication channels.
The Oracle Java ME SDK implements OBEX transfer over simulated Bluetooth and TCP connections.
For an example, see Section 15.3, "Running the OBEX Demo."
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 double-check on a CLDC device.
The device properties are displayed in the Properties pane.
Scroll down to see the Bluetooth and OBEX properties. When you click a property a description is shown in the 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 Enabled
Enable or disable Bluetooth functionality
Bluetooth Address
The Bluetooth address of this device.
Friendly Name
Set the friendly name of the device
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.
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 soft button 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.
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.