本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
}
示例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));
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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)));
}
示例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…");
}
示例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<>();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例15: toApi21
import android.bluetooth.le.ScanSettings; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanSettings toApi21() {
return new ScanSettings.Builder()
.setReportDelay(getReportDelayMillis())
.setScanMode(getScanMode())
.build();
}