Java Reference
In-Depth Information
Note The Java API for Bluetooth also adds L2CAPConnection and L2CAPConnectionNotifier for
working with the lower-level L2CAP protocol directly. Working with the lower-level L2CAP protocol is signifi-
cantly more difficult because you must work with packet size limit, handle fragmentation, and reassembly of
large messages yourself. L2CAP is often used directly by native applications that perform audio/video streaming.
L2CAPConnection uses the protocol specification “btl2cap://” in the GCF connection string. The RFCOMM
higher-level protocol simplifies application programming by providing a stream-based API and handling the
packet assembly details for you.
Instead of a port number, as in IP-based connections, the UUID of the service is specified
after the hostname, separated by a colon (:). A set of comma-separated connection parameters
can follow the UUID in the GCF connection string. Some more useful parameters include
authenticate , encrypt , authorize , and master .
You can obtain the ServiceRecord , if you have a notifier created by Connector.open() ,
using a method on the LocalDevice :
ServiceRecord getRecord(Connection notifier);
To register the ServiceRecord with the SDDB and wait for incoming connections, call the
blocking acceptAndOpen() method on the StreamConnectionNotifier .
StreamConnection conn = myNotifier.acceptAndOpen();
You can update the registered ServiceRecord in the SDDB using the LocalDevice method:
void updateRecord(ServiceRecord srvRecord);
The ServiceRecord for a service is removed from the SDDB when the
StreamConnectionNotifier is closed.
A Bluetooth Dating Service
The first example MIDlet creates a simple Bluetooth “dating service.” It is odd how sometimes
people in the same room who are attracted to each other are reluctant to start talking and
“break the ice.” This MIDlet may help.
You tell the MIDlet the type of date you're looking for, and the MIDlet will use Bluetooth to
query anybody who comes near you for compatibility. Once compatibility is established, your
potential date's e-mail address is displayed on your phone.
The MIDlet is called BTMIDlet . Create a new project called BTMIDlet and copy the two
source files into the src directory of the WTK. Build the project.
 
Search WWH ::




Custom Search