當前位置: 首頁>>代碼示例>>Java>>正文


Java ScanFilter類代碼示例

本文整理匯總了Java中android.bluetooth.le.ScanFilter的典型用法代碼示例。如果您正苦於以下問題:Java ScanFilter類的具體用法?Java ScanFilter怎麽用?Java ScanFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScanFilter類屬於android.bluetooth.le包,在下文中一共展示了ScanFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scanLeDevice

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
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();
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:20,代碼來源:BluetoothUtilImpl.java

示例2: scanDevice

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例3: beginScan

import android.bluetooth.le.ScanFilter; //導入依賴的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.ScanFilter; //導入依賴的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: getScanFilters

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
@NonNull
private List<ScanFilter> getScanFilters(final byte[] serviceData) {
    return Arrays.asList(
                new ScanFilter[]{
                        new ScanFilter.Builder()
                                .setServiceData(Constants.SERVICE_pUUID, serviceData)
                                .build()
                });
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:10,代碼來源:BTConnection.java

示例6: toApi21

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
@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();
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:21,代碼來源:ScanFilterCompat.java

示例7: searchBleDeviceByUUIDs

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例8: startScan

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例9: startScan

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例10: startScan

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例11: toApi21

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
@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();
}
 
開發者ID:joerogers,項目名稱:BluetoothCompat,代碼行數:21,代碼來源:ScanFilterCompat.java

示例12: startScanning

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例13: startScan

import android.bluetooth.le.ScanFilter; //導入依賴的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

示例14: startLeScan

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
@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);
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:13,代碼來源:BluetoothLeScanL21Proxy.java

示例15: scanLeDevice

import android.bluetooth.le.ScanFilter; //導入依賴的package包/類
/**
 * 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());
            }
        }
    }
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:43,代碼來源:PairingActivity.java


注:本文中的android.bluetooth.le.ScanFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。