本文整理汇总了Java中android.bluetooth.le.BluetoothLeScanner.startScan方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothLeScanner.startScan方法的具体用法?Java BluetoothLeScanner.startScan怎么用?Java BluetoothLeScanner.startScan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.le.BluetoothLeScanner
的用法示例。
在下文中一共展示了BluetoothLeScanner.startScan方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanDevice
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的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: startScan
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
public static void startScan(ScanCallback callback) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (null == adapter) {
Log.e(TAG, "BluetoothAdapter is null");
return;
}
BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
if (null == scanner) {
Log.e(TAG, "BluetoothLeScanner is null");
return;
}
scanner.startScan(callback);
}
示例3: startScan
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
@Override
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN,Manifest.permission.BLUETOOTH})
public void startScan(@NonNull ScanCallback callback) {
ScannerUtils.throwOnAdaptorNotEnabled(bluetoothAdapter);
final BluetoothLeScanner nativeScanner = getNativeScannerOrThrow();
throwIfCallbackInUse(callback);
ScanCallbackHolder holder = new ScanCallbackHolder(callback);
callbackHolderMap.put(callback,holder);
nativeScanner.startScan(holder.getNativeCallback());
}
示例4: startListeningBluetoothMeasurements
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void startListeningBluetoothMeasurements(List<ScanFilter> scanFilters,
ScanSettings scanSettings,
ScanCallback scanCallback){
BluetoothLeScanner scanner = bluetoothManager.getAdapter().getBluetoothLeScanner();
scanner.startScan(scanFilters, scanSettings, scanCallback);
}
示例5: startScan
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
private void startScan() {
BluetoothLeScanner bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanFilter.Builder builder = new ScanFilter.Builder();
Vector<ScanFilter> filter = new Vector<ScanFilter>();
filter.add(builder.build());
ScanSettings.Builder builderScanSettings = new ScanSettings.Builder();
builderScanSettings.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
builderScanSettings.setReportDelay(0);
bluetoothScanner.startScan(filter, builderScanSettings.build(), leScanCallback);
}
示例6: IllegalArgumentException
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
@Override
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH})
/* package */ void startScanInternal(final List<ScanFilter> filters, final ScanSettings settings, final ScanCallback callback) {
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
offloadedFilteringSupported = mBluetoothAdapter.isOffloadedFilteringSupported();
if (mWrappers.containsKey(callback)) {
throw new IllegalArgumentException("scanner already started with given callback");
}
final BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
if (scanner == null)
throw new IllegalStateException("BT le scanner not available");
final ScanCallbackWrapper wrapper = new ScanCallbackWrapper(filters, settings, callback);
final ScanCallbackImpl _callback = new ScanCallbackImpl();
final android.bluetooth.le.ScanSettings _settings = toImpl(mBluetoothAdapter, settings);
List<android.bluetooth.le.ScanFilter> _filters = null;
if (filters != null && mBluetoothAdapter.isOffloadedFilteringSupported() && settings.getUseHardwareFilteringIfSupported())
_filters = toImpl(filters);
mWrappers.put(callback, wrapper);
mCallbacks.put(callback, _callback);
mWrappers2.put(_callback, wrapper);
scanner.startScan(_filters, _settings, _callback);
}
开发者ID:NordicSemiconductor,项目名称:Android-Scanner-Compat-Library,代码行数:28,代码来源:BluetoothLeScannerImplLollipop.java
示例7: scanPeripheralWithServicesUUID_API21
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
public void scanPeripheralWithServicesUUID_API21(final String uuid) {
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
requestOpenBT();
return;
}
BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
List<ScanFilter> list = new ArrayList<ScanFilter>(1);
ScanCallback callback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, android.bluetooth.le.ScanResult result) {
BluetoothDevice device = result.getDevice();
ScanRecord sr = result.getScanRecord();
int rssi = result.getRssi();
// if (rssi > -15) {
// runCallbackWithErrorCode(BLEUtilErrorCode.E_RSSI_ERROR);
// return;
// }
// if (rssi < -35) {
// runCallbackWithErrorCode(BLEUtilErrorCode.E_RSSI_TOO_LOW);
// return;
// }
if (matchRules(rssi, sr.getBytes(), uuid)) {
connectToDevice(device);
}
}
@Override
public void onScanFailed(int errorCode) {
}
};
if (uuid != null) {
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(uuid)).build();
list.add(filter);
scanner.startScan(list, settings, callback);
} else {
// scanner.startScan(null, settings, callback);
scanner.startScan(callback);
}
}
示例8: startScan
import android.bluetooth.le.BluetoothLeScanner; //导入方法依赖的package包/类
/**
* Starts a BLE Scan. Discovered devices are reported via the delivered callback.
*
* @param callback An instance of the BleScanCallback, used to receive scan results.
* @param durationMs The duration in milliseconds, how long the scan should last. This parameter
* must be greater or equal to 1000 ms.
* @param deviceNameFilter A array of device names to filter for. Only BLE devices with these
* names are reported to the callback.
* @param advertisedServiceUuidFilter An Array of advertised service UUIDs to also deliver results for.
* @return true if a scan was triggered and false, if it was not possible to trigger a scan or
* if there is already an ongoing scan running.
*/
public boolean startScan(@NonNull final BleScanCallback callback, final long durationMs,
final String[] deviceNameFilter, final String[] advertisedServiceUuidFilter) {
if (mBluetoothAdapter == null) {
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
return false;
}
if (durationMs < MIN_SCAN_DURATION_MS) {
Log.w(TAG, "The scan duration must be longer than 1 second");
return false;
}
if (mStopScanningRunnable != null) {
Log.w(TAG, "Already a scan running");
return false;
}
final BluetoothLeScanner bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null) {
Log.w(TAG, "Failed to scan. Bluetooth appears to be unavailable");
return false;
}
final ScanSettings settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
final List<ScanFilter> filters = getScanFilters(deviceNameFilter, advertisedServiceUuidFilter);
// Stops scanning after a pre-defined scan period.
mStopScanningRunnable = new Runnable() {
@Override
public void run() {
stopScan(callback);
}
};
mScanHandler.postDelayed(mStopScanningRunnable, durationMs);
bluetoothLeScanner.startScan(filters, settings, callback);
return true;
}