以下是我开始扫描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;
}
};