| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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:
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:
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:
You can also lookup values and convert them to human friendly strings:
Note: The data can be found as ODS (Open Office Spreadsheets) in the documents folder.
You will need the following permissions to access the Bluetooth Hardware
In addition one of the following is needed from API 23 and above to scan for BT LE devices:
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.
| Back | FazBrowse Home | New Git URL |