Zum Inhalt

Java Bluetooth Scanner

Ein einfacher Bluetooth Scanner in Java. Die ursprüngliche (umfangreichere) Version ist vor gut einem Jahr im Seminar "Location Based Services" am IfGI in Münster von mir geschrieben wurden.

Es wird ein kompletter Scan durchgeführt, dessen Dauer ca. 11 Sekunden benötigt und dann alle gefundenen Bluetooth Geräte ausgibt, z.B. Handys, Headsets usw. halt. Dabei müssen diese Geräte nur ihre Bluetooth Schnittstelle aktiviert haben und sichtbar sein, um gefunden zu werden. Auf "Client Seite" muss also keine besondere Software laufen.

Auf "Server Seite" wird BlueCove benutzt, um Java etwas mehr Bluetooth beizubringen. 😉

— Short version in englisch following. —

A simple bluetooth scanner developed in java. The scan takes about 11 seconds to find all available devices in range. These devices must have an activated bluetooth interface and must be visible to other devices. No extra software is needed on client side. To provide bluetooth functionaliy, BlueCove is used.


If you’ve got any questions regarding this small piece of code, feel free to contact me!


1. BluetoothDeviceListener.java

package de.ifgi.ss2007.dwilmsmann.RIDE;

import javax.bluetooth.*;

public class BluetoothDeviceListener implements DiscoveryListener{

public void deviceDiscovered(RemoteDevice remoteDevice,
DeviceClass deviceClass) {
System.out.println(remoteDevice.getBluetoothAddress());
}

public void inquiryCompleted(int complete) {
}

public void servicesDiscovered(int transId, ServiceRecord[] records) {
}

public void serviceSearchCompleted(int transId, int complete) {
}

}


2. BluetoothScanner.java

package de.ifgi.ss2007.dwilmsmann.RIDE;

import javax.bluetooth.*;

public class BluetoothScanner {

private static LocalDevice localDevice = null;
private static DiscoveryAgent agent = null;

public void scanForDevices() {
try {
localDevice = LocalDevice.getLocalDevice();
agent = localDevice.getDiscoveryAgent();
agent.startInquiry(DiscoveryAgent.GIAC,
new BluetoothDeviceListener());
} catch (BluetoothStateException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

BluetoothScanner bs = new BluetoothScanner();
bs.scanForDevices();

}

}


3. Sources & sample application.

BluetoothScanner.zip

4. Kontakt / Contact

https://www.denniswilmsmann.de/
mailto:denniswilmsmann_AT_gmx.de

Published inJava

Schreibe den ersten Kommentar

    Schreibe einen Kommentar

    Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert


    The reCAPTCHA verification period has expired. Please reload the page.