當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。