以下是我开始扫描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;
}
};
答案 0 :(得分:2)
扫描一直持续到