当前位置: 首页>>代码示例>>Java>>正文


Java ScanSettings类代码示例

本文整理汇总了Java中android.bluetooth.le.ScanSettings的典型用法代码示例。如果您正苦于以下问题:Java ScanSettings类的具体用法?Java ScanSettings怎么用?Java ScanSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScanSettings类属于android.bluetooth.le包,在下文中一共展示了ScanSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scanDevice

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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);		
}
 
开发者ID:LedgerHQ,项目名称:u2f-ble-test,代码行数:17,代码来源:U2FBLEDevice.java

示例2: buildSettings

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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;
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:17,代码来源:L_Util.java

示例3: beginScan

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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);
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:17,代码来源:BluetoothGlucoseMeter.java

示例4: searchBleDeviceByNames

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:gradlman,项目名称:SensorLib,代码行数:22,代码来源:DsSensorManager.java

示例5: searchBleDeviceByUUIDs

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:gradlman,项目名称:SensorLib,代码行数:22,代码来源:DsSensorManager.java

示例6: startScan

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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));
}
 
开发者ID:haodynasty,项目名称:AndroidBleManager,代码行数:18,代码来源:BluetoothLeScannerCompat.java

示例7: startScan

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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);
            }
        }
    }
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:23,代码来源:NewBleDeviceAdapterImpl.java

示例8: startScan

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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);
            }
        }
    }
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:27,代码来源:NewBleDeviceAdapterImpl.java

示例9: concludesAtLimit

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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)));
}
 
开发者ID:hello,项目名称:android-buruberi,代码行数:23,代码来源:LollipopLePeripheralScannerTests.java

示例10: startScanning

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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…");
}
 
开发者ID:devunwired,项目名称:nearby-beacons,代码行数:21,代码来源:EddystoneScannerService.java

示例11: onResume

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@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<>();
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:12,代码来源:DeviceListActivity.java

示例12: startScan

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:martindisch,项目名称:SensorTag-Accelerometer,代码行数:15,代码来源:ScanFragment.java

示例13: RuuviTagScanner

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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();
    }
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:12,代码来源:RuuviTagScanner.java

示例14: buildBleScanResultCallbackTypeEnum

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
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();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:13,代码来源:MbsEnums.java

示例15: toApi21

import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanSettings toApi21() {
    return new ScanSettings.Builder()
            .setReportDelay(getReportDelayMillis())
            .setScanMode(getScanMode())
            .build();
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:8,代码来源:ScanSettingsCompat.java


注:本文中的android.bluetooth.le.ScanSettings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。