@Deprecated static ScanSettings.Builder buildSettings(BleManager mgr, int scanMode, Interval scanReportDelay) { final ScanSettings.Builder builder = new ScanSettings.Builder(); builder.setScanMode(scanMode); if( mgr.getNativeAdapter().isOffloadedScanBatchingSupported() ) { final long scanReportDelay_millis = false == Interval.isDisabled(scanReportDelay) ? scanReportDelay.millis() : 0; builder.setReportDelay(scanReportDelay_millis); } else { builder.setReportDelay(0); } return builder; }
protected static void scanDevice(BluetoothAdapter bluetoothAdapter, U2FBLEDeviceNotification notification, Logger logger, Context context, String data, ScanType scanType) { BluetoothLeScanner bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner(); ScanFilter.Builder builder = new ScanFilter.Builder(); switch(scanType) { case SCAN_BY_NAME: builder.setDeviceName(data); break; } Vector<ScanFilter> filter = new Vector<ScanFilter>(); filter.add(builder.build()); ScanSettings.Builder builderScanSettings = new ScanSettings.Builder(); builderScanSettings.setScanMode(ScanSettings.SCAN_MODE_BALANCED); builderScanSettings.setReportDelay(0); LocalScanCallback scannerCallback = new LocalScanCallback(bluetoothAdapter, logger, notification, context); bluetoothScanner.startScan(filter, builderScanSettings.build(), scannerCallback); }
private void beginScan() { if (Build.VERSION.SDK_INT >= 21) { if (d) Log.d(TAG, "Preparing for scan..."); // set up v21 scanner mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); filters = new ArrayList<>(); filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(GLUCOSE_SERVICE)).build()); } // all api versions scanLeDevice(true); }
public static void searchBleDeviceByNames(final SensorFoundCallback callback, String[] deviceNames) { //Log.e(TAG, "Searching for BLE device..."); List<ScanFilter> filterList = new ArrayList<>(); for (String name : deviceNames) { filterList.add(new ScanFilter.Builder().setDeviceName(name).build()); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { if (sBleScanner == null) { sBleScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner(); } if (sScanCallback == null) { sScanCallback = new DsScanCallback(callback); } if (sBleScanner != null) { sBleScanner.startScan(filterList, new ScanSettings.Builder().build(), sScanCallback); } } }
public static void searchBleDeviceByUUIDs(SensorFoundCallback callback, UUID[] uuids) { //Log.e(TAG, "Searching for BLE device..."); List<ScanFilter> filterList = new ArrayList<>(); for (UUID uuid : uuids) { filterList.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(uuid)).build()); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { if (sBleScanner == null) { sBleScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner(); } if (sScanCallback == null) { sScanCallback = new DsScanCallback(callback); } if (sBleScanner != null) { sBleScanner.startScan(filterList, new ScanSettings.Builder().build(), sScanCallback); } } }
@Override public void startScan(BluetoothAdapter adapter, List<ScanFilterCompat> filters, ScanSettingsCompat settings, ScanCallbackCompat callbackCompat) { List<ScanFilter> scanFilters = null; if (filters != null) { scanFilters = new ArrayList<>(filters.size()); for (ScanFilterCompat filter : filters) { scanFilters.add(filter.toApi21()); } } if (settings == null) { throw new IllegalStateException("Scan settings are null"); } ScanSettings scanSettings = settings.toApi21(); adapter.getBluetoothLeScanner().startScan(scanFilters, scanSettings, registerCallback(callbackCompat)); }
@Override public void startScan(final BleDeviceScanCallback callback) { mCallback = callback; final List<ScanFilter> filters = new ArrayList<>(); final ScanSettings settings = new ScanSettings.Builder().build(); mBleScanner = mBluetoothAdapter.getBluetoothLeScanner(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { if (mBleScanner != null) { mBleScanner.startScan(filters, settings, mScanCallback); } } else { // Unless required permissions were acquired, scan does not start. if (BleUtils.isBLEPermission(mContext)) { if (mBleScanner != null) { mBleScanner.startScan(filters, settings, mScanCallback); } } } }
@Override public void startScan(final BleDeviceScanCallback callback) { mCallback = callback; List<ScanFilter> filters = new ArrayList<ScanFilter>(); if (mServiceUuids != null && mServiceUuids.length > 0) { for (UUID uuid : mServiceUuids) { ScanFilter filter = new ScanFilter.Builder().setServiceUuid( new ParcelUuid(uuid)).build(); filters.add(filter); } } ScanSettings settings = new ScanSettings.Builder().build(); mBleScanner = mBluetoothAdapter.getBluetoothLeScanner(); if (mBleScanner != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { mBleScanner.startScan(filters, settings, mScanCallback); } else { // Unless required permissions were acquired, scan does not start. if (BleUtils.isBLEPermission(mContext)) { mBleScanner.startScan(filters, settings, mScanCallback); } } } }
@Test public void concludesAtLimit() { final ShadowBluetoothAdapterExt shadowAdapter = getShadowBluetoothAdapter(); final ShadowBluetoothLeScanner shadowScanner = BuruberiShadows.shadowOf(shadowAdapter.getBluetoothLeScanner()); final PeripheralCriteria criteria = new PeripheralCriteria(); criteria.setLimit(1); final LollipopLePeripheralScanner scanner = new LollipopLePeripheralScanner(stack, criteria); scanner.call(Subscribers.empty()); assertThat(shadowScanner.getScanCallbacks(), hasItem(scanner)); final BluetoothDevice device = Testing.createMockDevice(); final ScanResult scanResult = new ScanResult(device, Testing.EMPTY_SCAN_RECORD, Testing.RSSI_DECENT, SystemClock.elapsedRealtimeNanos()); scanner.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, scanResult); scanner.onConcludeScan(); assertThat(shadowScanner.getScanCallbacks(), not(hasItem(scanner))); }
private void startScanning() { List<ScanFilter> filters = new ArrayList<>(); //Filter on just our requested namespaces for (String namespace : NAMESPACE_IDS) { ScanFilter beaconFilter = new ScanFilter.Builder() .setServiceUuid(UID_SERVICE) .setServiceData(UID_SERVICE, getNamespaceFilter(namespace), NAMESPACE_FILTER_MASK) .build(); filters.add(beaconFilter); } //Run in background mode ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .build(); mBluetoothLeScanner.startScan(filters, settings, mScanCallback); if (DEBUG_SCAN) Log.d(TAG, "Scanning started…"); }
@Override protected void onResume() { super.onResume(); if (Build.VERSION.SDK_INT >= 21) { mLeScanner = mBtAdapter.getBluetoothLeScanner(); mScanSetting = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); mScanFilters = new ArrayList<>(); } }
/** * Initiates the scan for BLE devices according to the API level. */ private void startScan() { if (mRecyclerViewAdapter.getSize() == 0) mListener.onShowProgress(); if (Build.VERSION.SDK_INT < 21) { mBluetoothAdapter.startLeScan(mLeScanCallback); } else { // request BluetoothLeScanner if it hasn't been initialized yet if (mLeScanner == null) mLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); // start scan in low latency mode mLeScanner.startScan(new ArrayList<ScanFilter>(), new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(), mScanCallback); } }
public RuuviTagScanner(RuuviTagListener listener, Context context) { this.listener = listener; final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); if (useNewApi()) { bleScanner = bluetoothAdapter.getBluetoothLeScanner(); ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder(); scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY); scanSettings = scanSettingsBuilder.build(); } }
private static RpcEnum buildBleScanResultCallbackTypeEnum() { RpcEnum.Builder builder = new RpcEnum.Builder(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return builder.build(); } builder.add("CALLBACK_TYPE_ALL_MATCHES", ScanSettings.CALLBACK_TYPE_ALL_MATCHES); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { builder.add("CALLBACK_TYPE_FIRST_MATCH", ScanSettings.CALLBACK_TYPE_FIRST_MATCH); builder.add("CALLBACK_TYPE_MATCH_LOST", ScanSettings.CALLBACK_TYPE_MATCH_LOST); } return builder.build(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) ScanSettings toApi21() { return new ScanSettings.Builder() .setReportDelay(getReportDelayMillis()) .setScanMode(getScanMode()) .build(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setTitle(com.igrow.android.R.string.title_devices); mHandler = new Handler(); // Use this check to determine whether BLE is supported on the device. Then you can // selectively disable BLE-related features. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, com.igrow.android.R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, com.igrow.android.R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); finish(); return; } if (android.os.Build.VERSION.SDK_INT >= 21) { ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY); mScanSettings = scanSettingsBuilder.build(); mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void startLeScan() { List<ScanFilter> filters = new ArrayList<ScanFilter>(); ScanFilter filter = new ScanFilter.Builder().build(); filters.add(filter); ScanSettings settings = new ScanSettings.Builder().setScanMode(SCAN_MODE_LOW_LATENCY) .build(); mBluetoothLeScanner.startScan(filters, settings, mLeScanCallback); }
/** * Allows to start or stop scanning for a low energy device. * * @param enable True - start scanning, false - stop scanning. */ private void scanLeDevice(final boolean enable) { logi("scanLeDevice() :: enable = " + enable); if(enable) { //Start scanning. if(!setupBleController()) { logi("scanLeDevice() :: FAILED "); return; } if(!scanning) { logi("scanLeDevice :: Searching For " + newDeviceName.toLowerCase()); // Stops scanning after a pre-defined scan period. scanning = true; ((TextView) findViewById(R.id.search_microbit_step_3_title)) .setText(getString(R.string.searchingTitle)); handler.postDelayed(scanTimedOut, SCAN_PERIOD); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { bluetoothAdapter.startLeScan(getOldScanCallback()); } else { List<ScanFilter> filters = new ArrayList<>(); // TODO: play with ScanSettings further to ensure the Kit kat devices connectMaybeInit with higher success rate ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build(); leScanner.startScan(filters, settings, getNewScanCallback()); } } } else { //Stop scanning. if(scanning) { scanning = false; handler.removeCallbacks(scanTimedOut); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { bluetoothAdapter.stopLeScan(getOldScanCallback()); } else { leScanner.stopScan(getNewScanCallback()); } } } }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override protected void configureSensorSubscribeAndUnsubscribeBehaviors(FlowableEmitter<SensorRecord> subscriber) { List<ScanFilter> scanFilters = initializeScanFilters(); ScanSettings scanSettings = initializeScanSettings(); final ScanCallback scanCallback = initializeScanCallbackFor(subscriber); startListeningBluetoothMeasurements(scanFilters, scanSettings, scanCallback); addUnsuscribeCallbackFor(subscriber, scanCallback); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void startListeningBluetoothMeasurements(List<ScanFilter> scanFilters, ScanSettings scanSettings, ScanCallback scanCallback){ BluetoothLeScanner scanner = bluetoothManager.getAdapter().getBluetoothLeScanner(); scanner.startScan(scanFilters, scanSettings, scanCallback); }
private ScanSettings buildScanSettings() { ScanSettings.Builder builder = new ScanSettings.Builder(); builder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE); builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT); builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES); } return builder.build(); }
public void scanLeDevice(final boolean enable, final BluScanCallBack scanCallback) { List<ScanFilter> scanFilters = new ArrayList<>(); ScanFilter scanFilter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(UDOOBLE.UUID_SENSORS_SERV)).build(); scanFilters.add(scanFilter); ScanSettings scanSettings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); UdooBluException udooBluException = checkBluetooth(getApplicationContext()); if (udooBluException != null) { if (scanCallback != null) scanCallback.onError(udooBluException); } else { mLEScanner = mBtAdapter.getBluetoothLeScanner(); if (enable && mScanning.compareAndSet(false, true)) { mLEScanner.startScan(scanFilters, scanSettings, scanCallback); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { mLEScanner.stopScan(scanCallback); mScanning.set(false); if (scanCallback != null) scanCallback.onScanFinished(); } }, SCAN_PERIOD); } else { mScanning.set(false); mLEScanner.stopScan(scanCallback); if (scanCallback != null) scanCallback.onScanFinished(); } } }
private ScanSettings createScanSettings() { ScanSettings.Builder builder = new ScanSettings.Builder(); ScanSettings settings; builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY); builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE); builder.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT); settings = builder.build(); return settings; }
private void startScan(@NonNull StartScanRequest request) { if (getState() == State.SCANNING) { return; } ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .build(); mScanResults.clear(); try { BluetoothUtil.getBluetoothAdapter(getApplication()) .getBluetoothLeScanner() .startScan(PlenGattConstants.PLEN_FILTERS, settings, mScanCallback); } catch (ScenographyException e) { postErrorEvent(e); return; } Observable<Object> stopEvent = Observable.amb( Observable.timer(request.getTimeout(), request.getUnit()) .doOnNext(t -> stopScan(new StopScanRequest())), mState.asObservable() .skipWhile(state -> state != State.SCANNING) .skipWhile(state -> state != State.STOP)); mSubscriptions.add(stopEvent.first().subscribe()); mState.set(State.SCANNING); }
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) private static ScanCallbackType toScanCallbackType(int callbackType) { switch (callbackType) { case ScanSettings.CALLBACK_TYPE_ALL_MATCHES: return CALLBACK_TYPE_ALL_MATCHES; case ScanSettings.CALLBACK_TYPE_FIRST_MATCH: return CALLBACK_TYPE_FIRST_MATCH; case ScanSettings.CALLBACK_TYPE_MATCH_LOST: return CALLBACK_TYPE_MATCH_LOST; default: RxBleLog.w("Unknown callback type %d -> check android.bluetooth.le.ScanSettings"); return CALLBACK_TYPE_UNKNOWN; } }
@Deprecated public static void startNativeScan(BleManager mgr, int scanMode, Interval scanReportDelay, L_Util.ScanCallback listener) { final ScanSettings.Builder builder = L_Util.buildSettings(mgr, scanMode, scanReportDelay); builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES); builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE); builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT); final ScanSettings scanSettings = builder.build(); L_Util.startScan(mgr, scanSettings, listener); }
public static void startNativeScan(BluetoothAdapter adapter, int scanMode, Interval scanReportDelay, L_Util.ScanCallback listener) { final ScanSettings.Builder builder = L_Util.buildSettings(adapter, scanMode, scanReportDelay); builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES); builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE); builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT); final ScanSettings scanSettings = builder.build(); L_Util.startScan(adapter, scanSettings, listener); }
static ScanSettings.Builder buildSettings(BluetoothAdapter adapter, int scanMode, Interval scanReportDelay) { final ScanSettings.Builder builder = new ScanSettings.Builder(); builder.setScanMode(scanMode); if( adapter.isOffloadedScanBatchingSupported() ) { final long scanReportDelay_millis = false == Interval.isDisabled(scanReportDelay) ? scanReportDelay.millis() : 0; builder.setReportDelay(scanReportDelay_millis); } else { builder.setReportDelay(0); } return builder; }
@Override public void onStartScanning() { mScanner = getBluetoothAdapter().getBluetoothLeScanner(); List<ScanFilter> filters = new ArrayList<>(); for (BleServiceSpec spec : BluetoothSensor.SUPPORTED_SERVICES) { filters.add(new ScanFilter.Builder() .setServiceUuid(ParcelUuid.fromString(spec.getServiceId().toString())) .build()); } ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_BALANCED) .build(); mScanner.startScan(filters, settings, mCallback); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static int convertNativeStatusToCompat(int nativeStatus) { switch (nativeStatus) { case ScanSettings.CALLBACK_TYPE_FIRST_MATCH: return com.taptrack.tcmptappy.blescannercompat.ScanSettings.CALLBACK_TYPE_FIRST_MATCH; case ScanSettings.CALLBACK_TYPE_MATCH_LOST: return com.taptrack.tcmptappy.blescannercompat.ScanSettings.CALLBACK_TYPE_MATCH_LOST; default: case ScanSettings.CALLBACK_TYPE_ALL_MATCHES: return com.taptrack.tcmptappy.blescannercompat.ScanSettings.CALLBACK_TYPE_ALL_MATCHES; } }
private void startScan() { BluetoothLeScanner bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner(); ScanFilter.Builder builder = new ScanFilter.Builder(); Vector<ScanFilter> filter = new Vector<ScanFilter>(); filter.add(builder.build()); ScanSettings.Builder builderScanSettings = new ScanSettings.Builder(); builderScanSettings.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY); builderScanSettings.setReportDelay(0); bluetoothScanner.startScan(filter, builderScanSettings.build(), leScanCallback); }
public void setupBluetooth() { getTransmitterDetails(); if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { //First time using the app or bluetooth was turned off? Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); Timer single_timer = new Timer(); single_timer.schedule(new TimerTask() { @Override public void run() { if (mBluetoothAdapter != null) mBluetoothAdapter.enable(); } }, 1000); single_timer.schedule(new TimerTask() { @Override public void run() { setupBluetooth(); } }, 10000); } else { if (Build.VERSION.SDK_INT >= 21) { mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); filters = new ArrayList<>(); //Only look for CGM. //filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build()); String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId); filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build()); } // unbond here to avoid clashes when we are mid-connection if (alwaysUnbond()) { forgetDevice(); } JoH.ratelimit("G5-timeout",0);//re-init to ensure onStartCommand always executes cycleScan cycleScan(0); } }
@TargetApi(21) private void scanLeDeviceLollipop(final boolean enable) { if (enable) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { lollipopScanner = bluetooth_adapter.getBluetoothLeScanner(); } if(lollipopScanner != null) { Log.d(TAG, "Starting scanner 21"); // Stops scanning after a pre-defined scan period. mHandler.postDelayed(new Runnable() { @Override public void run() { is_scanning = false; if(bluetooth_adapter != null && bluetooth_adapter.isEnabled()) { lollipopScanner.stopScan(mScanCallback); } invalidateOptionsMenu(); } }, SCAN_PERIOD); ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); is_scanning = true; lollipopScanner.startScan(null, settings, mScanCallback); } else { try { scanLeDevice(true); } catch (Exception e) { Log.e(TAG, "Failed to scan for ble device", e); } } } else { is_scanning = false; if(bluetooth_adapter != null && bluetooth_adapter.isEnabled()) { lollipopScanner.stopScan(mScanCallback); } } invalidateOptionsMenu(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static ScanSettings getScanSettings() { final ScanSettings.Builder builder = new ScanSettings.Builder(); builder.setReportDelay(0); builder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); return builder.build(); }
private void initScanData() { scanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, ScanResult result) { super.onScanResult(callbackType, result); Log.i(TAG, "onScanResult" + result); String address = result.getDevice().getAddress(); String name; ScanRecord scanRecord = result.getScanRecord(); name = scanRecord == null ? "unknown" : scanRecord.getDeviceName(); scanResultListener.onResultReceived(name, address); } @Override public void onBatchScanResults(List<ScanResult> results) { super.onBatchScanResults(results); Log.e(TAG, "onBatchScanResults"); } @Override public void onScanFailed(int errorCode) { super.onScanFailed(errorCode); Log.e(TAG, "onScanFailed"); scanResultListener.onScanFailed(errorCode); } }; filters = new ArrayList<>(); filters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE)).build()); scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); }