Recently, I’ve created yet another reactive library for Android. It’s called ReactiveBeacons and it’s responsible for observing BLE (Bluetooth Low Energy) beacons. Beacons are small devices, which became quite popular in the last years. They can be utilized in creating Contextual Awareness, Contextual Computing and Internet of Things. Beacons have lithium battery, are constantly turned on and emit signals via Bluetooth all the time. ReactiveBeacons library allows to transform these signals into Observable stream compatible with RxJava. Whenever new beacon is detected or RSSI (Received signal strength indication) changes, new immutable beacon data is emitted.

Usage of the library inside the Activity is simple:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private Subscription subscription;

@Override protected void onResume() {
super.onResume();

// optionally, we can request Bluetooth Access
reactiveBeacons.requestBluetoothAccessIfDisabled(this);

subscription = reactiveBeacons.observe()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Beacon>() {
@Override public void call(Beacon beacon) {
// do something with beacon
}
});
}

We also have to remember to unregister subscription correctly in order to stop BLE scan, which can drain the battery.

1
2
3
4
@Override protected void onPause() {
super.onPause();
subscription.unsubscribe();
}

If you want to use this library in your project, add the following dependency to your build.gradle file.

1
2
3
dependencies {
compile 'com.github.pwittchen:reactivebeacons:0.0.1'
}

Don’t forget to add dependency to RxAndroid if you want to use Android-specific features of RxJava.

Source code of the library can be found at: https://github.com/pwittchen/ReactiveBeacons.

Any new issues or pull requests are welcome!

Happy coding!