@Override
            public void subscribe(final ObservableEmitter<BleAdapterState> emitter) {
                final BroadcastReceiver receiver = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
                        BleAdapterState internalState = mapToBleAdapterState(state);
                        RxBleLog.i("Adapter state changed: %s", internalState);
                        emitter.onNext(internalState);
                    }
                };
                context.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
                emitter.setCancellable(new Cancellable() {
                    @Override
                    public void cancel() {
                        context.unregisterReceiver(receiver);
                    }
                });
            }
Observes Bluetooth adapter state. This responds to user interactions as well as system controlled state changes.
<p>
NOTE: Make sure that this Observable is unsubscribed according to the Activity lifecycle. It internally uses BroadcastReceiver, so
it is required that it us unregistered before onDestroy.
rxandroidble/src/main/java/com/polidea/rxandroidble2/RxBleAdapterStateObservable.java