本文整理匯總了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;
}