gpt4 book ai didi

Android:如何获取蓝牙扫描状态?

转载 作者:搜寻专家 更新时间:2023-11-01 09:27:00 24 4
gpt4 key购买 nike

这是我开始扫描 BLE 设备的方式

    if(bluetoothLeScanner!=null) {
bluetoothLeScanner.startScan(scanCallback);
isScanning = true;
}

如何以及何时将 isScanning 设置为 false?

有没有办法在 scanCallback 中找到它?

private ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, final ScanResult result) {
super.onScanResult(callbackType, result);
if(result==null) return;
runOnUiThread(new Runnable() {
@Override
public void run() {
bluetoothDeviceAdapter.update(result.getDevice());
bluetoothDeviceAdapter.notifyDataSetChanged();
}
});

// This doesn't mean end of scan does it?
// isScanning = false;
}

@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
final List<BluetoothDevice> deviceList = new ArrayList<>();
for(ScanResult result: results)
deviceList.add(result.getDevice());
runOnUiThread(new Runnable() {
@Override
public void run() {
bluetoothDeviceAdapter.updateBatch(deviceList);
bluetoothDeviceAdapter.notifyDataSetChanged();
}
});

// This doesn't mean end of scan does it?
// isScanning = false;
}
};

最佳答案

扫描运行到

  1. 您明确阻止它。
  2. 调用 onScanFailed 回调。
  3. 蓝牙已关闭。

关于Android:如何获取蓝牙扫描状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49835558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com