Structure of Bluetooth MIDlet

This document will give you an overview of the structure in a Java/Bluetooth MIDlet. General knowledge about MIDlets is required. You'll find several MIDlet examples at:

http://developers.sun.com/techtopics/mobility/reference/codesamples/index.html

Overview

Usually an event-driven MIDlet looks like this:

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

public class yourMidlet extends MIDlet implements CommandListener {

	public void startApp() {

	}

	public void pauseApp() {

	}

	public void destroyApp() {

	}

	public void commandAction(Command c, Displayable d) {

	}
}

When creating a Bluetooth MIDlet you will need to implement the DiscoveryListener interface. An object implementing this interface is used for device discovery (inquiring) and service searches. Your MIDlet will now look like this:

import javax.bluetooth.DiscoveryListener;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

public class yourMidlet extends MIDlet implements CommandListener,
						  DiscoveryListener {

        public void startApp() {

        }

        public void pauseApp() {

        }

        public void destroyApp() {

        }

        public void commandAction(Command c, Displayable d) {

        }

	public void deviceDiscovered(RemoteDevice remoteDevice, 
				     DeviceClass deviceClass) {

	}

	public void inquiryCompleted(int param) {

	}

	public void serviceSearchCompleted(int param, int param1) {

	}

	public void servicesDiscovered(int param, 
				       ServiceRecord[] serviceRecord) {

	}

}

To summarize this structure:

The first three methods, startApp(), pauseApp() and destroyApp() are needed for any MIDlet. They come from extending the MIDlet class.

The next method, commandAction() comes from the CommandListener interface. This is needed to catch command-events.

The last four methods, deviceDiscovered(), inquiryCompleted(), serviceSearchCompleted() and servicesDiscovered() are used to catch events during device discovery and service search. Device discovery and service search will be outlined in the documents Inquiry and Service search.



This page was last updated 14. Jul. 2006

Comments and feedback are highly appreciated.

You can reach me at: klings (at) nowires (dot) org

Most pages on this site, in particular the How-To's, are available primarily for archival purposes.

Klings.NoWires.Code()

Home

J2ME CDC CLDC MIDP 1.0 MIDP 2.0 MIDlets JABWT

Bluetooth

BTBrowser BTBenchmark KlingsLib

Code Structure Inquiry Service
search
RFCOMM Pitfalls Service record usage Service record manipulation

Devices Developers

Tools Rococo IDEs WTK NDS Antenna

How-To Bluez OBEX Eclipse NetBeans JBuilder WAP

About me