@NonNull private List<ScanFilter> getScanFilters(final byte[] serviceData) { return Arrays.asList( new ScanFilter[]{ new ScanFilter.Builder() .setServiceData(Constants.SERVICE_pUUID, serviceData) .build() }); }
void scanLeDevice(final boolean enable) { Timber.d("scanLeDevice enable = " + enable); if (enable) { mScanning = true; List<ScanFilter> filters_v2 = new ArrayList<>(); ScanFilter scanFilter = new ScanFilter.Builder() .setServiceUuid(ParcelUuid.fromString(OWDevice.OnewheelServiceUUID)) .build(); filters_v2.add(scanFilter); //c03f7c8d-5e96-4a75-b4b6-333d36230365 mBluetoothLeScanner.startScan(filters_v2, settings, mScanCallback); } else { mScanning = false; mBluetoothLeScanner.stopScan(mScanCallback); // added 10/23 to try cleanup mBluetoothLeScanner.flushPendingScanResults(mScanCallback); } mainActivity.invalidateOptionsMenu(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public ScanFilter toApi21() { ScanFilter.Builder builder = new ScanFilter.Builder(); if (mDeviceName != null) { builder.setDeviceName(mDeviceName); } if (mServiceUuid != null) { builder.setServiceUuid(mServiceUuid, mServiceUuidMask); } if (mDeviceAddress != null) { builder.setDeviceAddress(mDeviceAddress); } if (mServiceDataUuid != null) { builder.setServiceData(mServiceDataUuid, mServiceData, mServiceDataMask); } if (mManufacturerId < 0) { builder.setManufacturerData(mManufacturerId, mManufacturerData, mManufacturerDataMask); } return builder.build(); }
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); } } } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) ScanFilter toApi21() { ScanFilter.Builder builder = new ScanFilter.Builder(); if (mDeviceName != null) { builder.setDeviceName(mDeviceName); } if (mServiceUuid != null) { builder.setServiceUuid(mServiceUuid, mServiceUuidMask); } if (mDeviceAddress != null) { builder.setDeviceAddress(mDeviceAddress); } if (mServiceDataUuid != null) { builder.setServiceData(mServiceDataUuid, mServiceData, mServiceDataMask); } if (mManufacturerId < 0) { builder.setManufacturerData(mManufacturerId, mManufacturerData, mManufacturerDataMask); } return builder.build(); }
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…"); }
/** * 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); } }
@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); }
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(); } } }
@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); }
public static List<com.taptrack.tcmptappy.blescannercompat.ScanFilter> getCompatScanFilter() { com.taptrack.tcmptappy.blescannercompat.ScanFilter.Builder builder = new com.taptrack.tcmptappy.blescannercompat.ScanFilter.Builder(); builder.setServiceUuid(new ParcelUuid(TappyVersions.VersionOne.TRUCONNECT_SERVICE_UUID)); List<com.taptrack.tcmptappy.blescannercompat.ScanFilter> list = new ArrayList<com.taptrack.tcmptappy.blescannercompat.ScanFilter>(1); list.add(builder.build()); return list; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static List<ScanFilter> getScanFilter() { ScanFilter.Builder builder = new ScanFilter.Builder(); builder.setServiceUuid(new ParcelUuid(TappyVersions.VersionOne.TRUCONNECT_SERVICE_UUID)); List<ScanFilter> list = new ArrayList<ScanFilter>(1); list.add(builder.build()); return list; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static List<ScanFilter> convertCompatScanFilterListToNative(List<com.taptrack.tcmptappy.blescannercompat.ScanFilter> compatFilters) { if(compatFilters == null) return null; List<ScanFilter> nativeFilters = new ArrayList<>(compatFilters.size()); for (com.taptrack.tcmptappy.blescannercompat.ScanFilter compatFilter : compatFilters) { nativeFilters.add(convertCompatScanFilterToNative(compatFilter)); } return nativeFilters; }
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); } }
private List<ScanFilter> createScanFilters() { ScanFilter.Builder builder = new ScanFilter.Builder(); builder.setServiceUuid(new ParcelUuid(serviceUUID)); ArrayList<ScanFilter> scanFilters = new ArrayList<>(); scanFilters.add(builder.build()); return scanFilters; }
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(); }
private void startScan() { //Scan for devices advertising the thermometer service ScanFilter beaconFilter = new ScanFilter.Builder() .setServiceUuid(TemperatureBeacon.THERM_SERVICE) .build(); ArrayList<ScanFilter> filters = new ArrayList<ScanFilter>(); filters.add(beaconFilter); ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); mBluetoothLeScanner.startScan(filters, settings, mScanCallback); }
public void resumeScan() { if (mBleAdapter == null || !mBleAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); mContext.startActivity(enableBtIntent); } else { if (Build.VERSION.SDK_INT >= 21) { mLEScanner = mBleAdapter.getBluetoothLeScanner(); mSettings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); mFilters = new ArrayList<ScanFilter>(); } scanLeDevice(true); } }
private List<ScanFilter> scanFilters() { ScanFilter filter; List<ScanFilter> list = new ArrayList<ScanFilter>(new BeaconStorage().getBeaconList().size()); for (BeaconDevice d: new BeaconStorage().getBeaconList()) { filter = new ScanFilter.Builder().setDeviceAddress(d.getMac()).build(); list.add(filter); } return list; }
@Implementation @RequiresPermission(Manifest.permission.BLUETOOTH) public void startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback) { if (adapter.getState() != BluetoothAdapter.STATE_ON) { throw new IllegalStateException("BT Adapter is not turned ON"); } scanCallbacks.add(callback); }
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() { 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()); } cycleScan(0); } }
public Ble(Context c, BleListener i, String deviceUuid, String r, String t) { context = c; iface = i; superPanelUuid = ParcelUuid.fromString(deviceUuid); rxUUid = UUID.fromString(r); txUUid = UUID.fromString(t); adapter = BluetoothAdapter.getDefaultAdapter(); scanner = adapter.getBluetoothLeScanner(); ScanFilter.Builder filter = new ScanFilter.Builder(); filter.setServiceUuid(superPanelUuid); ScanFilter.Builder superPanelFilter = new ScanFilter.Builder(); superPanelFilter.setServiceUuid(superPanelUuid); ScanSettings.Builder settings = new ScanSettings.Builder(); settings.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); List<ScanFilter> filters = new ArrayList<ScanFilter>(); filters.add(filter.build()); //filters.add(superPanelFilter.build()); if(scanner == null) { System.out.println("Failed to get LE scanner"); return; } scanner.startScan(filters, settings.build(), scanCallback); }
public void startScan( List<ScanFilter> filters, int scanSettingsScanMode, ScanCallbackWrapper callback) { ScanSettings settings = new ScanSettings.Builder().setScanMode(scanSettingsScanMode).build(); ForwardScanCallbackToWrapper callbackForwarder = new ForwardScanCallbackToWrapper(callback); mCallbacks.put(callback, callbackForwarder); mScanner.startScan(filters, settings, callbackForwarder); }
public void scanBTLEDevices(final boolean enable) { if(bluetoothAdapter == null || bluetoothAdapter.getBluetoothLeScanner() == null) { Log.d("BTLE", "Bluetooth adapter or scanner were null!"); return; } if(enable) { // only scan for 5 seconds handler.postDelayed(new Runnable() { @Override public void run() { scanBTLEDevices(false); } }, 5000); //scanning = true; setScanning(true); bluetoothDevices.clear(); deviceRSSIs.clear(); adapter.notifyDataSetChanged(); // filter explicitly for the UART List<ScanFilter> filters = new ArrayList<ScanFilter>(); filters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")).build()); // setup the scan settings ScanSettings settings = new ScanSettings.Builder().setReportDelay(0).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); bluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, scanCallback); } else { //scanning = false; setScanning(false); bluetoothAdapter.getBluetoothLeScanner().stopScan(scanCallback); } }
private void startScan() { //Return only Eddystone beacons matching the filter ScanFilter beaconFilter = new ScanFilter.Builder() .setServiceUuid(UID_SERVICE) .setServiceData(UID_SERVICE, Beacon.FRAME_FILTER, Beacon.FILTER_MASK) .build(); List<ScanFilter> filters = Collections.singletonList(beaconFilter); ScanSettings settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build(); mBluetoothLeScanner.startScan(filters, settings, mScanCallback); }