Java 类android.bluetooth.le.ScanSettings 实例源码

项目:AsteroidOSSync    文件:L_Util.java   
@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;
}
项目:u2f-ble-test    文件:U2FBLEDevice.java   
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);       
}
项目:xDrip    文件:BluetoothGlucoseMeter.java   
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);
}
项目:xDrip-plus    文件:BluetoothGlucoseMeter.java   
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);
}
项目:SensorLib    文件:DsSensorManager.java   
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);
        }
    }
}
项目:SensorLib    文件:DsSensorManager.java   
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);
        }
    }
}
项目:AndroidBleManager    文件:BluetoothLeScannerCompat.java   
@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));
}
项目:DeviceConnect-Android    文件:NewBleDeviceAdapterImpl.java   
@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);
            }
        }
    }
}
项目:DeviceConnect-Android    文件:NewBleDeviceAdapterImpl.java   
@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);
            }
        }
    }
}
项目:BluetoothCompat    文件:BluetoothLeScannerCompat.java   
@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));
}
项目:android-buruberi    文件:LollipopLePeripheralScannerTests.java   
@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)));
}
项目:nearby-beacons    文件:EddystoneScannerService.java   
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…");
}
项目:SweetBlue    文件:L_Util.java   
@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;
}
项目:AndroidSDK2.0    文件:DeviceListActivity.java   
@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<>();
    }
}
项目:SensorTag-Accelerometer    文件:ScanFragment.java   
/**
 * 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);
    }
}
项目:com.ruuvi.station    文件:RuuviTagScanner.java   
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();
    }
}
项目:mobly-bundled-snippets    文件:MbsEnums.java   
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();
}
项目:AndroidMuseumBleManager    文件:ScanSettingsCompat.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanSettings toApi21() {
    return new ScanSettings.Builder()
            .setReportDelay(getReportDelayMillis())
            .setScanMode(getScanMode())
            .build();
}
项目:igrow-android    文件:DeviceScanActivity.java   
@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();
    }
}
项目:igrow-android    文件:BluetoothLeScanL21Proxy.java   
@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);
}
项目:microbit    文件:PairingActivity.java   
/**
 * 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());
            }
        }
    }
}
项目:AndroidSensors    文件:BLEMeasurementsGatherer.java   
@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);
}
项目:AndroidSensors    文件:BLEMeasurementsGatherer.java   
@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);
}
项目:noise    文件:BluetoothSyncService.java   
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();
}
项目:UDOOBluLib-android    文件:UdooBluService.java   
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();
        }
    }
}
项目:mesh-core-on-android    文件:JniCallbacks.java   
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;
}
项目:plen-Scenography_Android    文件:PlenScanService.java   
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);
}
项目:RxAndroidBle    文件:InternalScanResultCreator.java   
@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;
    }
}
项目:AsteroidOSSync    文件:M_Util.java   
@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);
}
项目:AsteroidOSSync    文件:M_Util.java   
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);
}
项目:AsteroidOSSync    文件:L_Util.java   
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;
}
项目:science-journal    文件:DeviceDiscovererV21.java   
@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);
}
项目:TappyBLE    文件:LollipopUtils.java   
@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;
    }
}
项目:u2f-ble-test    文件:MainActivity.java   
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);
}
项目:xDrip    文件:G5CollectionService.java   
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);
        }
    }
项目:xDrip    文件:BluetoothScan.java   
@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();
}
项目:xDrip-plus    文件:G5CollectionService.java   
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);
        }
    }
项目:xDrip-plus    文件:BluetoothScan.java   
@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();
}
项目:ibeacon-scanner-android    文件:DefaultScanService.java   
@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();
}
项目:Android-BLE-Library    文件:BLEScanner.java   
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();
}