Anda di halaman 1dari 2

import java.io.

*; public void inquiryCompleted(int param) {


import javax.microedition.midlet.*; try {
import javax.microedition.lcdui.*; switch (param) {
import javax.microedition.io.*; case
import javax.bluetooth.*; DiscoveryListener.INQUIRY_COMPLETED:
import java.util.*;
public class Blue extends MIDlet implements if
CommandListener,DiscoveryListener (devicesFound.size() > 0) {
{
private List activeDevices; activeDevices.addCommand(select);
private Command select,exit;
private Display display; activeDevices.setSelectCommand(select);
private LocalDevice local=null; }
private DiscoveryAgent agent = null; else {
private Vector devicesFound = null; activeDevices.append("No Devices Found", null); }
private ServiceRecord[] servicesFound = null; break; }
private String connectionURL = null; }
public void startApp() { catch (Exception e) {}
display = }
Display.getDisplay(this); public void serviceSearchCompleted(int
activeDevices = new List("Active transID, int respCode) {}
Devices", List.IMPLICIT); public void servicesDiscovered(int transID,
select = new Command("Search ServiceRecord[] serviceRecord) {}
Again", Command.OK, 0); public void deviceDiscovered(RemoteDevice
exit = new Command("Exit", remoteDevice, DeviceClass deviceClass) {
Command.EXIT, 0); String str = null;
try {
activeDevices.addCommand(exit); str =
remoteDevice.getBluetoothAddress() + " - ";
activeDevices.setCommandListener(this); str +=
try { remoteDevice.getFriendlyName(true);
local = } catch (Exception e) {}
LocalDevice.getLocalDevice(); } activeDevices.append(str, null);
catch (Exception e) {}
doDeviceDiscovery(); devicesFound.addElement(remoteDevice);
if (!agent.startInquiry(DiscoveryAgent.GIAC, this)) {}
display.setCurrent(activeDevices); }
} private void doDeviceDiscovery() {
try {
public void pauseApp() {} local =
public void destroyApp(boolean unconditional) LocalDevice.getLocalDevice();
{ notifyDestroyed(); } agent =
public void commandAction(Command cmd, local.getDiscoveryAgent();
Displayable disp) { devicesFound =
if (cmd == select && disp == new Vector();
activeDevices) { } catch (Exception e) {}
}
activeDevices.deleteAll(); }
doDeviceDiscovery();
}
if (cmd == exit) {
destroyApp(false); }
}
Output:

Anda mungkin juga menyukai