Skip to content

Discoverability and scan mode

Ivan Baranov edited this page Dec 15, 2015 · 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(Action.isEqualTo(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE))
      .subscribe(new Action1<Integer>() {
        @Override public void call(Integer scanMode) {
          //
        }
      });

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 Action1<Integer>() {
        @Override public void call(Integer scanMode) {
          //switch (scanMode) {
        }
      });