@ SuppressLint ( "MissingPermission" ) @ RequiresPermission ( anyOf = { ACCESS_COARSE_LOCATION , ACCESS_FINE_LOCATION } ) public Observable < Beacon > observe ( ) { if ( ! isBleSupported ( ) ) { return Observable . empty ( ) ; } if ( isAtLeastAndroidLollipop ( ) ) { scanStrategy = new LollipopScanStrategy ( bluetoothAdapter ) ; } else { scanStrategy = new PreLollipopScanStrategy ( bluetoothAdapter ) ; } try { return observe ( scanStrategy ) ; } catch ( SecurityException e ) { return Observable . empty ( ) ; } }
Creates an observable stream of BLE beacons which can be subscribed with RxJava Uses appropriate BLE scan strategy according to Android version installed on a device