Skip to content

Discoverability and scan mode

Ivan Baranov edited this page Jun 21, 2017 · 2 revisions

To issue a request to make the local device discoverable to other devices for default 120 seconds, call enableDiscoverability(activity, requestCode).

To issue a request to make the local device discoverable to other devices for custom duration, call enableDiscoverability(activity, requestCode, duration). Maximum duration is capped at 300 seconds.

See also ACTION_REQUEST_DISCOVERABLE.

To observe single scan mode:

rxBluetooth.observeScanMode()
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeOn(Schedulers.computation())
    .filter(BtPredicate.in(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE))
    .subscribe(new Consumer<Integer>() {
    @Override public void accept(Integer integer) throws Exception {
      //
    }
    });

You can observe single or multiple scan modes:

BluetoothAdapter.SCAN_MODE_NONE
BluetoothAdapter.SCAN_MODE_CONNECTABLE
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE

To observe all scan modes:

rxBluetooth.observeScanMode()
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeOn(Schedulers.computation())
    .subscribe(new Consumer<Integer>() {
    @Override public void accept(Integer integer) throws Exception {
        //switch (scanMode) { }
    }
    });