How to Connect two Mobile Devices via Bluetooth in J2ME?

Bluetooth is a low-cost, short-range wireless technology that has become popular among those who want to create personal area networks (PANs). Java provides many APIs for the Bluetooth Connection. The core Java Bluetooth APIs, can be found in javax.bluetooth under JSR82. JSR 82 requires the Connected Limited Device Configuration (CLDC) as its lowest common denominator, and the Connected Device Configuration (CDC) is a superset of CLDC, so JABWT can be implemented on top of both CLDC- and CDC-based profiles.

There are basic procedure for establishing the connection via Bluetooth. These are listed below

    • The first step is the Device Discovery.
      • retrieveDevices() retrieves already discovered or known devices that are nearby.
      • startInquiry() initiates discovery of nearby devices, also called inquiry.
      • cancelInquiry() cancels any inquiry presently in progress.
      • deviceDiscovered() indicates whether a device has been discovered.
      • inquiryCompleted() indicates whether the inquiry has succeeded, triggered an error, or been canceled.

The DiscoveryAgent class supports discovery of both devices and services. DiscoveryAgent’s device discovery methods are used to initiate and cancel device discovery: The Bluetooth Discovery Agent invokes the DiscoveryListener’s device – discovery callback methods at different points in the inquiry phase: Device discovery begins with a call to startInquiry(). As the inquiry progresses, the Bluetooth Discovery Agent invokes the callback methods deviceDiscovered() and inquiryCompleted() as appropriate.

    • Once the device is discovered, then the two devices connect to each other.

For this purpose, one device will be the local device while the other Remote Device. The localdevice will provide a service of specified UUID and the remote device search for this specified UUID. Once the UUID is found, the two device accept and establish connection.

Leave a Reply

Your email address will not be published. Required fields are marked *