
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
github.com/alt236/bluetooth-le-library---android
Advanced tools
This library allows for easy access to a Bluetooth LE device's Advertisement Records. It also offers:
This will only work on devices with Android 4.3 (API Level 18) and above.
⚠️ BREAKING CHANGES ⚠️
As of version 2.0.0, the library package name has been changed from uk.co.alt236.bluetoothlelib.*
to dev.alt236.bluetoothlelib.*.
The maven coordinates have also changed due to the migration to Maven Central (see below).
This project is available as an artifact for use with Gradle. To use that, add the following blocks to your build.gradle file:
dependencies {
compile 'dev.alt236:bluetooth-le-library-android:2.0.0'
}
If you really need a Jar file, fork the project and execute ./gradlew clean build generateRelease at the root of the project.
This will create a zip file under <PROJECT_ROOT>/library/build/ the Jar can be found inside.
In the onLeScan() method of your BluetoothAdapter.LeScanCallback() create a new BluetoothLeDevice with the given information.
For example:
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
final BluetoothLeDevice deviceLe = new BluetoothLeDevice(device, rssi, scanRecord, System.currentTimeMillis());
runOnUiThread(new Runnable() {
@Override
public void run() {
mDeviceStore.addDevice(deviceLe);
mLeDeviceListAdapter.replaceData(mDeviceStore.getDeviceList());
}
});
}
};
Once you have created a device, you can access the following methods:
getAddress() : Gets the MAC Address of the devicegetAdRecordStore(): Gives access to a device's Ad RecordsgetDevice(): Gives access to the standard BluetoothDevice objectgetFirstRssi(): Retrieves the RSSI value which was used when the object was createdgetFirstTimestamp() Retrieves the timestamp (in millis) which was used when the object was createdgetRssi() Gets the current RSSI measurement (see note below).getScanRecord() Retrieves the RAW scan record arraygetTimestamp() Gets the timestamp of the last RSSI measurementgetRunningAverageRssi() Retrieves the internally calculated running average RSSI value (see note below).Note: The Running Average RSSI is not updated automatically (i.e. the library does not monitor on its own in the background). To add another measurement, you need to call updateRssiReading(long timestamp, int rssiReading).
Once you've created a BluetoothLe device, you can access the AdRecord store via the leDevice.getAdRecordStore(). Once you have the AdRecordStore you can use the following methods:
getRecord(int recordNo): Gets the AdRecord object corresponding to the recordNumber.getRecordDataAsString(int recordNo) : Gets the AdRecord contents as a String (expect non printable characters in most cases).isRecordPresent(int recordNo): Checks to see if a record exists.Note: Record numbers are declared in the Bluetooth 4 spec which can be found here.
They are also declared as constants in AdRecord.java.
You can check if a device is an iBeacon by using BeaconUtils.getBeaconType(BluetootLeDevice device). Once you have confirmed that it is, you can create a new IBeaconDevice via the IBeaconDevice constructor.
Example Flow:
final BluetoothLeDevice device = ... // A generic BLE device
if (BeaconUtils.getBeaconType(device) == BeaconType.IBEACON) {
final IBeaconDevice iBeacon = new IBeaconDevice(device);
// DO STUFF
}
An IBeaconDevice extends BluetoothLeDevice, so you still have access to the same methods as before. In addition you can do the following:
getAccuracy(): Gets the estimated Accuracy of the reading in meters based on a simple running average calculationgetCalibratedTxPower(): Gets the calibrated TX power of the iBeacon device as reportedgetCompanyIdentifier(): Gets the iBeacon company identifier (this should always be 0x004C for Apple)getDistanceDescriptor(): Gets the estimated Distance descriptor (an enum)getIBeaconData(): Gets the raw IBeaconManufacturerData object.getUUID(): Gets the device's UUIDgetMajor(): Gets the device's Major valuegetMinor(): Gets the device's Minor valueYou can also lookup values and convert them to human friendly strings:
BluetoothClassResolver.resolveDeviceClass(int btClass): Will try to resolve a Blueotooth Device classCompanyIdentifierResolver.getCompanyName(int companyId, String fallback): Will try to resolve a Company identifier to the company nameGattAttributeResolver.getAttributeName(String uuid, String fallback): Will try to convert a UUID to its name.Note: The data can be found as ODS (Open Office Spreadsheets) in the documents folder.
dev.alt236.bluetoothlelib.*)You will need the following permissions to access the Bluetooth Hardware
android.permission.BLUETOOTHandroid.permission.BLUETOOTH_ADMINIn addition one of the following is needed from API 23 and above to scan for BT LE devices:
android.permission.ACCESS_COARSE_LOCATIONandroid.permission.ACCESS_FINE_LOCATION Author: Alexandros Schillings.
All logos are the property of their respective owners.
The code in this project is licensed under the Apache Software License 2.0.
Copyright (c) 2014-2017 Alexandros Schillings.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.