本文整理匯總了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();
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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()
});
}
示例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();
}
示例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);
}
}
}
示例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));
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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();
}
示例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…");
}
示例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);
}
}
示例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);
}
示例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());
}
}
}
}