public interface BleService
Example
String uuid = UUID.randomUUID().toString(); // for example a known UUID of a beacon
Services.get(BleService.class).ifPresent(service -> {
service.startScanning(new Configuration(uuid), scanResult -> {
System.out.printf("major: %d, minor: %d, proximity: %s",
scanResult.getMajor(), scanResult.getMinor(),
scanResult.getProximity().name());
});
});
Android Configuration
The permissions android.permission.BLUETOOTH
and
android.permission.BLUETOOTH_ADMIN
need to be added.
<manifest ...>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
...
</manifest>
iOS Configuration
The following keys are required:
<key>NSLocationUsageDescription</key>
<string>Reason to use Location Service (iOS 6+)</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Reason to use Location Service (iOS 8+)</string>
Modifier and Type | Method and Description |
---|---|
void |
startScanning(Configuration configuration,
java.util.function.Consumer<ScanDetection> callback)
Start scanning for BLE devices.
|
void |
stopScanning()
Stops the last called startScanning operation.
|
void startScanning(Configuration configuration, java.util.function.Consumer<ScanDetection> callback)
configuration
- provide setting options to filter the beacons to be scannedcallback
- provided function that will be called once a beacon is detectedvoid stopScanning()