Skip to content

2.35.17 and Later

Custom Bluetooth Scanning

In addition to using the BleScanner class, it is now also possible to implement a custom solution for BLE scanning as well. The Tapkey Mobile SDK for Android contains utility classes to detect and filter for Tapkey-enabled locks.

Using a custom BLE Scanner gives the application developer finer control over the scanning process and makes its details more transparent. It is therefore the recommended way of implementing BLE scanning functionality.

The SDK provides functionality that allows to obtain a list of ScanFilter instances which can be used with Android's native BLE scanning functionality. Obtain the list by using the TapkeyBleAdvertisingFormat class as follows:

// Retrieve the TapkeyBleAdvertisingFormat from the TapkeyServiceFactory instance
TapkeyBleAdvertisingFormat advertisingFormat = tapkeyServiceFactory.getTapkeyBleAdvertisingFormat();

// Get Android ScanFilters
List<ScanFilter> scanFilters = ScanFilters.getAndroidScanFilters(advertisingFormat.getScanFilters())

// Apply the Scanfilters when starting the BLE scan
bluetoothLeScanner.startScan(scanFilters, scanSettings, scanCallback);

The TapkeyBleAdvertisingParser can then be used as follows to detect if the discovered BluetoothLE device is a Tapkey-enabled lock and for obtaining its physicalLockId.

// Get the TapkeyBleAdvertisingParser
TapkeyBleAdvertisingFormat advertisingFormat = tapkeyServiceFactory.getTapkeyBleAdvertisingFormat();
TapkeyBleAdvertisingParser advertisingParser = advertisingFormat.getAdvertisingParser();

// Parse the advertising data of the BLE device
TapkeyAdvertisingData data = advertisingParser.parseAdvertisingData(scanRecord.getBytes())

// If the parsed data is not null, the discovered device is likely to be a Tapkey-enabled locking device.
if (data != null) {
    String physicalLockId = data.getPhysicalLockId();